"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "message/Message.cpp" between
muscle7.41.zip and muscle7.50.zip

About: MUSCLE (Multi User Server Client Linking Environment) is a messaging server and networking API. The included server program ("muscled") lets its clients message each other, and/or store information in its serverside hierarchical database.

Message.cpp  (muscle7.41):Message.cpp  (muscle7.50)
skipping to change at line 104 skipping to change at line 104
FixedSizeDataArray() {/* empty */} FixedSizeDataArray() {/* empty */}
virtual ~FixedSizeDataArray() {/* empty */} virtual ~FixedSizeDataArray() {/* empty */}
virtual uint32 GetNumItems() const {return _data.GetNumItems();} virtual uint32 GetNumItems() const {return _data.GetNumItems();}
virtual void Clear(bool releaseDataBuffers) {_data.Clear(releaseDataBuffers); } virtual void Clear(bool releaseDataBuffers) {_data.Clear(releaseDataBuffers); }
virtual void Normalize() {_data.Normalize();} virtual void Normalize() {_data.Normalize();}
virtual status_t AddDataItem(const void * item, uint32 size) virtual status_t AddDataItem(const void * item, uint32 size)
{ {
return (size == sizeof(DataType)) ? (item ? _data.AddTail(*(reinterpret_ca st<const DataType *>(item))) : _data.AddTail()) : B_ERROR; return (size == sizeof(DataType)) ? (item ? _data.AddTail(*(reinterpret_ca st<const DataType *>(item))) : _data.AddTail()) : B_BAD_ARGUMENT;
} }
virtual status_t PrependDataItem(const void * item, uint32 size) virtual status_t PrependDataItem(const void * item, uint32 size)
{ {
return (size == sizeof(DataType)) ? (item ? _data.AddHead(*(reinterpret_ca st<const DataType *>(item))) : _data.AddHead()) : B_ERROR; return (size == sizeof(DataType)) ? (item ? _data.AddHead(*(reinterpret_ca st<const DataType *>(item))) : _data.AddHead()) : B_BAD_ARGUMENT;
} }
virtual uint32 GetItemSize(uint32 /*index*/) const {return sizeof(DataType);} virtual uint32 GetItemSize(uint32 /*index*/) const {return sizeof(DataType);}
virtual status_t RemoveDataItem(uint32 index) {return _data.RemoveItemAt(inde x);} virtual status_t RemoveDataItem(uint32 index) {return _data.RemoveItemAt(inde x);}
virtual status_t FindDataItem(uint32 index, const void ** setDataLoc) const virtual status_t FindDataItem(uint32 index, const void ** setDataLoc) const
{ {
if (index < _data.GetNumItems()) if (index < _data.GetNumItems())
{ {
*setDataLoc = &_data[index]; *setDataLoc = &_data[index];
return (*setDataLoc) ? B_NO_ERROR : B_ERROR; return (*setDataLoc) ? B_NO_ERROR : B_DATA_NOT_FOUND;
} }
return B_ERROR; return B_DATA_NOT_FOUND;
} }
virtual status_t ReplaceDataItem(uint32 index, const void * data, uint32 size ) virtual status_t ReplaceDataItem(uint32 index, const void * data, uint32 size )
{ {
return (size == sizeof(DataType)) ? _data.ReplaceItemAt(index, *(static_ca st<const DataType *>(data))) : B_ERROR; return (size == sizeof(DataType)) ? _data.ReplaceItemAt(index, *(static_ca st<const DataType *>(data))) : B_BAD_ARGUMENT;
} }
virtual bool ElementsAreFixedSize() const {return true;} virtual bool ElementsAreFixedSize() const {return true;}
virtual bool IsFlattenable() const {return true;} virtual bool IsFlattenable() const {return true;}
const DataType & ItemAt(int i) const {return _data[i];} const DataType & ItemAt(int i) const {return _data[i];}
FixedSizeDataArray<DataType> & operator=(const FixedSizeDataArray<DataType> & rhs) FixedSizeDataArray<DataType> & operator=(const FixedSizeDataArray<DataType> & rhs)
{ {
skipping to change at line 245 skipping to change at line 245
// Flattenable interface // Flattenable interface
virtual uint32 FlattenedSize() const {return this->_data.GetNumItems() * Flat ItemSize;} virtual uint32 FlattenedSize() const {return this->_data.GetNumItems() * Flat ItemSize;}
virtual status_t Unflatten(const uint8 * buffer, uint32 numBytes) virtual status_t Unflatten(const uint8 * buffer, uint32 numBytes)
{ {
this->_data.Clear(); this->_data.Clear();
if (numBytes % FlatItemSize) if (numBytes % FlatItemSize)
{ {
LogTime(MUSCLE_LOG_DEBUG, "FixedSizeDataArray %p: Unexpected numBytes " UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC "\n", this, numBytes, FlatItemSize); LogTime(MUSCLE_LOG_DEBUG, "FixedSizeDataArray %p: Unexpected numBytes " UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC "\n", this, numBytes, FlatItemSize);
return B_ERROR; // length must be an even multiple of item size, or so mething's wrong! return B_BAD_ARGUMENT; // length must be an even multiple of item size , or something's wrong!
} }
DataType temp; DataType temp;
const uint32 numItems = numBytes / FlatItemSize; const uint32 numItems = numBytes / FlatItemSize;
if (this->_data.EnsureSize(numItems) == B_NO_ERROR) status_t ret;
if (this->_data.EnsureSize(numItems).IsOK(ret))
{ {
for (uint32 i=0; i<numItems; i++) for (uint32 i=0; i<numItems; i++)
{ {
if ((temp.Unflatten(buffer, FlatItemSize) != B_NO_ERROR)||(this->_da ta.AddTail(temp) != B_NO_ERROR)) if ((temp.Unflatten(buffer, FlatItemSize).IsError(ret))||(this->_dat a.AddTail(temp).IsError(ret)))
{ {
LogTime(MUSCLE_LOG_DEBUG, "FixedSizeDataArray %p: Error unflatte LogTime(MUSCLE_LOG_DEBUG, "FixedSizeDataArray %p: Error unflatte
ned item " UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC "\n", this, i, numItems); ned item " UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC " [%s]\n", this, i, numItem
return B_ERROR; s, ret());
break;
} }
buffer += FlatItemSize; buffer += FlatItemSize;
} }
return B_NO_ERROR;
} }
else return B_ERROR; return ret;
} }
virtual uint32 TypeCode() const {return ItemTypeCode;} virtual uint32 TypeCode() const {return ItemTypeCode;}
protected: protected:
virtual void AddToString(String & s, uint32, int indent) const virtual void AddToString(String & s, uint32, int indent) const
{ {
const uint32 numItems = this->GetNumItems(); const uint32 numItems = this->GetNumItems();
for (uint32 i=0; i<numItems; i++) for (uint32 i=0; i<numItems; i++)
{ {
skipping to change at line 323 skipping to change at line 323
break; break;
} }
} }
virtual status_t Unflatten(const uint8 * buffer, uint32 numBytes) virtual status_t Unflatten(const uint8 * buffer, uint32 numBytes)
{ {
this->_data.Clear(); this->_data.Clear();
if (numBytes % sizeof(DataType)) if (numBytes % sizeof(DataType))
{ {
LogTime(MUSCLE_LOG_DEBUG, "PrimitiveTypeDataArray %p: Unexpected numBy tes " UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC "\n", this, numBytes, (uint32) s izeof(DataType)); LogTime(MUSCLE_LOG_DEBUG, "PrimitiveTypeDataArray %p: Unexpected numBy tes " UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC "\n", this, numBytes, (uint32) s izeof(DataType));
return B_ERROR; // length must be an even multiple of item size, or so mething's wrong! return B_BAD_ARGUMENT; // length must be an even multiple of item size , or something's wrong!
} }
status_t ret;
const uint32 numItems = numBytes / sizeof(DataType); const uint32 numItems = numBytes / sizeof(DataType);
if (this->_data.EnsureSize(numItems, true) == B_NO_ERROR) if (this->_data.EnsureSize(numItems, true).IsOK(ret))
{ {
// Note that typically you can't rely on the contents of a Queue object to // Note that typically you can't rely on the contents of a Queue object to
// be stored in a single, contiguous field like this, but in this case we've // be stored in a single, contiguous field like this, but in this case we've
// called Clear() and then EnsureSize(), so we know that the field's he adPointer // called Clear() and then EnsureSize(), so we know that the field's he adPointer
// is at the front of the field, and we are safe to do this. --jaf // is at the front of the field, and we are safe to do this. --jaf
ConvertFromNetworkByteOrder(this->_data.HeadPointer(), reinterpret_cast <const DataType *>(buffer), numItems); ConvertFromNetworkByteOrder(this->_data.HeadPointer(), reinterpret_cast <const DataType *>(buffer), numItems);
return B_NO_ERROR; return B_NO_ERROR;
} }
else return B_ERROR; else return ret;
} }
// Flattenable interface // Flattenable interface
virtual uint32 FlattenedSize() const {return this->_data.GetNumItems() * size of(DataType);} virtual uint32 FlattenedSize() const {return this->_data.GetNumItems() * size of(DataType);}
protected: protected:
virtual void ConvertToNetworkByteOrder(void * writeToHere, const void * readF romHere, uint32 numItems) const = 0; virtual void ConvertToNetworkByteOrder(void * writeToHere, const void * readF romHere, uint32 numItems) const = 0;
virtual void ConvertFromNetworkByteOrder(void * writeToHere, const void * rea dFromHere, uint32 numItems) const = 0; virtual void ConvertFromNetworkByteOrder(void * writeToHere, const void * rea dFromHere, uint32 numItems) const = 0;
virtual const char * GetFormatString() const = 0; virtual const char * GetFormatString() const = 0;
skipping to change at line 462 skipping to change at line 463
virtual void Flatten(uint8 * buffer) const virtual void Flatten(uint8 * buffer) const
{ {
const uint32 numItems = _data.GetNumItems(); const uint32 numItems = _data.GetNumItems();
for (uint32 i=0; i<numItems; i++) buffer[i] = (uint8) (_data[i] ? 1 : 0); for (uint32 i=0; i<numItems; i++) buffer[i] = (uint8) (_data[i] ? 1 : 0);
} }
virtual status_t Unflatten(const uint8 * buffer, uint32 numBytes) virtual status_t Unflatten(const uint8 * buffer, uint32 numBytes)
{ {
_data.Clear(); _data.Clear();
if (_data.EnsureSize(numBytes) == B_NO_ERROR) status_t ret;
{ if (_data.EnsureSize(numBytes).IsOK(ret))
for (uint32 i=0; i<numBytes; i++) if (_data.AddTail((buffer[i] != 0) ? for (uint32 i=0; i<numBytes; i++)
true : false) != B_NO_ERROR) return B_ERROR; if (_data.AddTail((buffer[i] != 0) ? true : false).IsError(ret)) bre
return B_NO_ERROR; ak;
}
else return B_ERROR; return ret;
} }
// Flattenable interface // Flattenable interface
virtual uint32 FlattenedSize() const {return _data.GetNumItems()*sizeof(uint8 );} /* bools are always flattened into 1 byte each */ virtual uint32 FlattenedSize() const {return _data.GetNumItems()*sizeof(uint8 );} /* bools are always flattened into 1 byte each */
virtual uint32 CalculateChecksum(bool /*countNonFlattenableFields*/) const virtual uint32 CalculateChecksum(bool /*countNonFlattenableFields*/) const
{ {
uint32 ret = TypeCode() + GetNumItems(); uint32 ret = TypeCode() + GetNumItems();
for (int32 i=GetNumItems()-1; i>=0; i--) ret += ((i+1)*(_data[i] ? 1 : 0)) ; for (int32 i=GetNumItems()-1; i>=0; i--) ret += ((i+1)*(_data[i] ? 1 : 0)) ;
return ret; return ret;
skipping to change at line 793 skipping to change at line 794
void SetTypeCode(uint32 tc) {_typeCode = tc;} void SetTypeCode(uint32 tc) {_typeCode = tc;}
virtual uint32 TypeCode() const {return _typeCode;} virtual uint32 TypeCode() const {return _typeCode;}
virtual status_t Unflatten(const uint8 * buffer, uint32 numBytes) virtual status_t Unflatten(const uint8 * buffer, uint32 numBytes)
{ {
Clear(false); Clear(false);
uint32 readOffset = 0; uint32 readOffset = 0;
status_t ret;
uint32 numItems; uint32 numItems;
if (ReadData(buffer, numBytes, &readOffset, &numItems, sizeof(numItems)) ! = B_NO_ERROR) if (ReadData(buffer, numBytes, &readOffset, &numItems, sizeof(numItems)).I sError(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "ByteBufferDataArray %p: Error reading numIt LogTime(MUSCLE_LOG_DEBUG, "ByteBufferDataArray %p: Error reading numIt
ems (numBytes=" UINT32_FORMAT_SPEC ")\n", this, numBytes); ems (numBytes=" UINT32_FORMAT_SPEC ") [%s]\n", this, numBytes, ret());
return B_ERROR; return ret;
} }
numItems = B_LENDIAN_TO_HOST_INT32(numItems); numItems = B_LENDIAN_TO_HOST_INT32(numItems);
for (uint32 i=0; i<numItems; i++) for (uint32 i=0; i<numItems; i++)
{ {
uint32 readFs; uint32 readFs;
if (ReadData(buffer, numBytes, &readOffset, &readFs, sizeof(readFs)) != B_NO_ERROR) if (ReadData(buffer, numBytes, &readOffset, &readFs, sizeof(readFs)).Is Error(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "ByteBufferDataArray %p: Error reading it LogTime(MUSCLE_LOG_DEBUG, "ByteBufferDataArray %p: Error reading it
em size (i=" UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC ", readOffset=" UINT32_FO em size (i=" UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC ", readOffset=" UINT32_FO
RMAT_SPEC ", numBytes=" UINT32_FORMAT_SPEC ")\n", this, i, numItems, readOffset, RMAT_SPEC ", numBytes=" UINT32_FORMAT_SPEC ") ret=[%s]\n", this, i, numItems, re
numBytes); adOffset, numBytes, ret());
return B_ERROR; return ret;
} }
readFs = B_LENDIAN_TO_HOST_INT32(readFs); readFs = B_LENDIAN_TO_HOST_INT32(readFs);
if (readOffset + readFs > numBytes) if (readOffset + readFs > numBytes)
{ {
LogTime(MUSCLE_LOG_DEBUG, "ByteBufferDataArray %p: Item size too la rge (i=" UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC ", readOffset=" UINT32_FORMAT _SPEC ", numBytes=" UINT32_FORMAT_SPEC ", readFs=" UINT32_FORMAT_SPEC ")\n", thi s, i, numItems, readOffset, numBytes, readFs); LogTime(MUSCLE_LOG_DEBUG, "ByteBufferDataArray %p: Item size too la rge (i=" UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC ", readOffset=" UINT32_FORMAT _SPEC ", numBytes=" UINT32_FORMAT_SPEC ", readFs=" UINT32_FORMAT_SPEC ")\n", thi s, i, numItems, readOffset, numBytes, readFs);
return B_ERROR; // message size too large for our buffer... corrupt ion? return B_BAD_DATA; // message size too large for our buffer... corr uption?
} }
FlatCountableRef fcRef(GetByteBufferFromPool(readFs, &buffer[readOffset ]).GetRefCountableRef(), true); FlatCountableRef fcRef(GetByteBufferFromPool(readFs, &buffer[readOffset ]).GetRefCountableRef(), true);
if ((fcRef())&&(AddDataItem(&fcRef, sizeof(fcRef)) == B_NO_ERROR)) read if ((fcRef())&&(AddDataItem(&fcRef, sizeof(fcRef)).IsOK(ret))) readOffs
Offset += readFs; et += readFs;
else retu else return r
rn B_ERROR; et;
} }
return B_NO_ERROR; return B_NO_ERROR;
} }
static void AddItemDescriptionToString(uint32 indent, uint32 idx, const FlatC ountableRef & fcRef, String & s) static void AddItemDescriptionToString(uint32 indent, uint32 idx, const FlatC ountableRef & fcRef, String & s)
{ {
AddItemPreambleToString(indent, idx, s); AddItemPreambleToString(indent, idx, s);
FlatCountable * fc = fcRef(); FlatCountable * fc = fcRef();
ByteBuffer temp; ByteBuffer temp;
skipping to change at line 922 skipping to change at line 925
MessageDataArray() {/* empty */} MessageDataArray() {/* empty */}
virtual ~MessageDataArray() {/* empty */} virtual ~MessageDataArray() {/* empty */}
/** For backwards compatibility with older muscle streams */ /** For backwards compatibility with older muscle streams */
virtual bool ShouldWriteNumItems() const {return false;} virtual bool ShouldWriteNumItems() const {return false;}
virtual status_t Unflatten(const uint8 * buffer, uint32 numBytes) virtual status_t Unflatten(const uint8 * buffer, uint32 numBytes)
{ {
Clear(false); Clear(false);
status_t ret;
uint32 readOffset = 0; uint32 readOffset = 0;
while(readOffset < numBytes) while(readOffset < numBytes)
{ {
uint32 readFs; uint32 readFs;
if (ReadData(buffer, numBytes, &readOffset, &readFs, sizeof(readFs)) != B_NO_ERROR) if (ReadData(buffer, numBytes, &readOffset, &readFs, sizeof(readFs)).Is Error(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "MessageDataArray %p: Read of sub-message LogTime(MUSCLE_LOG_DEBUG, "MessageDataArray %p: Read of sub-message
size failed (readOffset=" UINT32_FORMAT_SPEC ", numBytes=" UINT32_FORMAT_SPEC " size failed (readOffset=" UINT32_FORMAT_SPEC ", numBytes=" UINT32_FORMAT_SPEC "
)\n", this, readOffset, numBytes); ) ret=[%s]\n", this, readOffset, numBytes, ret());
return B_ERROR; return ret;
} }
readFs = B_LENDIAN_TO_HOST_INT32(readFs); readFs = B_LENDIAN_TO_HOST_INT32(readFs);
if (readOffset + readFs > numBytes) if (readOffset + readFs > numBytes)
{ {
LogTime(MUSCLE_LOG_DEBUG, "MessageDataArray %p: Sub-message size to o large (readOffset=" UINT32_FORMAT_SPEC ", numBytes=" UINT32_FORMAT_SPEC ", rea dFs=" UINT32_FORMAT_SPEC ")\n", this, readOffset, numBytes, readFs); LogTime(MUSCLE_LOG_DEBUG, "MessageDataArray %p: Sub-message size to o large (readOffset=" UINT32_FORMAT_SPEC ", numBytes=" UINT32_FORMAT_SPEC ", rea dFs=" UINT32_FORMAT_SPEC ")\n", this, readOffset, numBytes, readFs);
return B_ERROR; // message size too large for our buffer... corrupt ion? return B_BAD_DATA; // message size too large for our buffer... corr uption?
} }
MessageRef nextMsg = GetMessageFromPool(); MessageRef nextMsg = GetMessageFromPool();
if (nextMsg()) if (nextMsg())
{ {
if (nextMsg()->Unflatten(&buffer[readOffset], readFs) != B_NO_ERROR) if (nextMsg()->Unflatten(&buffer[readOffset], readFs).IsError(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "MessageDataArray %p: Sub-message unfl LogTime(MUSCLE_LOG_DEBUG, "MessageDataArray %p: Sub-message unfl
atten failed (readOffset=" UINT32_FORMAT_SPEC ", numBytes=" UINT32_FORMAT_SPEC " atten failed (readOffset=" UINT32_FORMAT_SPEC ", numBytes=" UINT32_FORMAT_SPEC "
, readFs=" UINT32_FORMAT_SPEC ")\n", this, readOffset, numBytes, readFs); , readFs=" UINT32_FORMAT_SPEC ") ret=[%s]\n", this, readOffset, numBytes, readFs
return B_ERROR; , ret());
return ret;
} }
if (AddDataItem(&nextMsg, sizeof(nextMsg)) != B_NO_ERROR) return B_E RROR; if (AddDataItem(&nextMsg, sizeof(nextMsg)).IsError(ret)) return ret;
readOffset += readFs; readOffset += readFs;
} }
else return B_ERROR; else RETURN_OUT_OF_MEMORY;
} }
return B_NO_ERROR; return B_NO_ERROR;
} }
static void AddItemDescriptionToString(uint32 indent, uint32 i, const Message Ref & msgRef, String & s, uint32 maxRecurseLevel) static void AddItemDescriptionToString(uint32 indent, uint32 i, const Message Ref & msgRef, String & s, uint32 maxRecurseLevel)
{ {
AddItemPreambleToString(indent, i, s); AddItemPreambleToString(indent, i, s);
const Message * msg = msgRef(); const Message * msg = msgRef();
if (msg) if (msg)
skipping to change at line 1058 skipping to change at line 1063
return sum; return sum;
} }
virtual status_t Unflatten(const uint8 * buffer, uint32 inputBufferBytes) virtual status_t Unflatten(const uint8 * buffer, uint32 inputBufferBytes)
{ {
this->Clear(false); this->Clear(false);
uint32 networkByteOrder; uint32 networkByteOrder;
uint32 readOffset = 0; uint32 readOffset = 0;
if (this->ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrde status_t ret;
r, sizeof(networkByteOrder)) != B_NO_ERROR)
if (this->ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrde
r, sizeof(networkByteOrder)).IsError(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "VariableSizeFlatObjectArray %p: Read of num LogTime(MUSCLE_LOG_DEBUG, "VariableSizeFlatObjectArray %p: Read of num
Elements failed (inputBufferBytes=" UINT32_FORMAT_SPEC ")\n", this, inputBufferB Elements failed (inputBufferBytes=" UINT32_FORMAT_SPEC ") ret=[%s]\n", this, inp
ytes); utBufferBytes, ret());
return B_ERROR; return ret;
} }
const uint32 numElements = B_LENDIAN_TO_HOST_INT32(networkByteOrder); const uint32 numElements = B_LENDIAN_TO_HOST_INT32(networkByteOrder);
if (this->_data.EnsureSize(numElements) != B_NO_ERROR) return B_ERROR; if (this->_data.EnsureSize(numElements).IsError(ret)) return ret;
for (uint32 i=0; i<numElements; i++) for (uint32 i=0; i<numElements; i++)
{ {
if (this->ReadData(buffer, inputBufferBytes, &readOffset, &networkByteO rder, sizeof(networkByteOrder)) != B_NO_ERROR) if (this->ReadData(buffer, inputBufferBytes, &readOffset, &networkByteO rder, sizeof(networkByteOrder)).IsError(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "VariableSizeFlatObjectArray %p: Read of LogTime(MUSCLE_LOG_DEBUG, "VariableSizeFlatObjectArray %p: Read of
element size failed (inputBufferBytes=" UINT32_FORMAT_SPEC ", i=" UINT32_FORMAT_ element size failed (inputBufferBytes=" UINT32_FORMAT_SPEC ", i=" UINT32_FORMAT_
SPEC "/" UINT32_FORMAT_SPEC ")\n", this, inputBufferBytes, i, numElements); SPEC "/" UINT32_FORMAT_SPEC ") ret=[%s]\n", this, inputBufferBytes, i, numElemen
return B_ERROR; ts, ret());
return ret;
} }
const uint32 elementSize = B_LENDIAN_TO_HOST_INT32(networkByteOrder); const uint32 elementSize = B_LENDIAN_TO_HOST_INT32(networkByteOrder);
if (elementSize == 0) if (elementSize == 0)
{ {
LogTime(MUSCLE_LOG_DEBUG, "VariableSizeFlatObjectArray %p: Element size was zero! (inputBufferBytes=" UINT32_FORMAT_SPEC ", i=" UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC ")\n", this, inputBufferBytes, i, numElements); LogTime(MUSCLE_LOG_DEBUG, "VariableSizeFlatObjectArray %p: Element size was zero! (inputBufferBytes=" UINT32_FORMAT_SPEC ", i=" UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC ")\n", this, inputBufferBytes, i, numElements);
return B_ERROR; // it should always have at least the trailing NUL byte! return B_BAD_DATA;
} }
// read element data // read element data
if ((readOffset + elementSize > inputBufferBytes)||(this->_data.AddTail () != B_NO_ERROR)||(this->_data.TailPointer()->Unflatten(&buffer[readOffset], el ementSize) != B_NO_ERROR)) if (readOffset + elementSize > inputBufferBytes)
{ {
LogTime(MUSCLE_LOG_DEBUG, "VariableSizeFlatObjectArray %p: Element size was too large! (inputBufferBytes=" UINT32_FORMAT_SPEC ", i=" UINT32_FORMAT_ SPEC "/" UINT32_FORMAT_SPEC ", readOffset=" UINT32_FORMAT_SPEC ", elementSize=" UINT32_FORMAT_SPEC ")\n", this, inputBufferBytes, i, numElements, readOffset, el ementSize); LogTime(MUSCLE_LOG_DEBUG, "VariableSizeFlatObjectArray %p: Element size was too large! (inputBufferBytes=" UINT32_FORMAT_SPEC ", i=" UINT32_FORMAT_ SPEC "/" UINT32_FORMAT_SPEC ", readOffset=" UINT32_FORMAT_SPEC ", elementSize=" UINT32_FORMAT_SPEC ")\n", this, inputBufferBytes, i, numElements, readOffset, el ementSize);
return B_ERROR; return B_BAD_DATA;
}
// parse element data
if ((this->_data.AddTail().IsError(ret))||(this->_data.TailPointer()->U
nflatten(&buffer[readOffset], elementSize).IsError(ret)))
{
LogTime(MUSCLE_LOG_DEBUG, "VariableSizeFlatObjectArray %p: Error un
flattening element! (inputBufferBytes=" UINT32_FORMAT_SPEC ", i=" UINT32_FORMAT_
SPEC "/" UINT32_FORMAT_SPEC ", readOffset=" UINT32_FORMAT_SPEC ", elementSize="
UINT32_FORMAT_SPEC ") ret=[%s]\n", this, inputBufferBytes, i, numElements, readO
ffset, elementSize, ret());
return ret;
} }
readOffset += elementSize; readOffset += elementSize;
} }
return B_NO_ERROR; return B_NO_ERROR;
} }
}; };
class StringDataArray : public VariableSizeFlatObjectArray<String> class StringDataArray : public VariableSizeFlatObjectArray<String>
{ {
public: public:
skipping to change at line 1150 skipping to change at line 1165
what = rhs.what; what = rhs.what;
_entries = rhs._entries; _entries = rhs._entries;
for (HashtableIterator<String, MessageField> iter(_entries); iter.HasData( ); iter++) iter.GetValue().EnsurePrivate(); // a copied Message shouldn't share data for (HashtableIterator<String, MessageField> iter(_entries); iter.HasData( ); iter++) iter.GetValue().EnsurePrivate(); // a copied Message shouldn't share data
} }
return *this; return *this;
} }
status_t Message :: GetInfo(const String & fieldName, uint32 * type, uint32 * c, bool * fixedSize) const status_t Message :: GetInfo(const String & fieldName, uint32 * type, uint32 * c, bool * fixedSize) const
{ {
const MessageField * field = GetMessageField(fieldName, B_ANY_TYPE); const MessageField * field = GetMessageField(fieldName, B_ANY_TYPE);
if (field == NULL) return B_ERROR; if (field == NULL) return B_DATA_NOT_FOUND;
if (type) *type = field->TypeCode(); if (type) *type = field->TypeCode();
if (c) *c = field->GetNumItems(); if (c) *c = field->GetNumItems();
if (fixedSize) *fixedSize = field->ElementsAreFixedSize(); if (fixedSize) *fixedSize = field->ElementsAreFixedSize();
return B_NO_ERROR; return B_NO_ERROR;
} }
uint32 Message :: GetNumNames(uint32 type) const uint32 Message :: GetNumNames(uint32 type) const
{ {
if (type == B_ANY_TYPE) return _entries.GetNumItems(); if (type == B_ANY_TYPE) return _entries.GetNumItems();
skipping to change at line 1249 skipping to change at line 1264
// Make sure the problem isn't that there already exists a field, but of the wrong type... // Make sure the problem isn't that there already exists a field, but of the wrong type...
// If that's the case, we can't create a same-named field of a different type , so fail. // If that's the case, we can't create a same-named field of a different type , so fail.
return _entries.PutIfNotAlreadyPresent(fieldName, MessageField(tc)); return _entries.PutIfNotAlreadyPresent(fieldName, MessageField(tc));
} }
status_t Message :: Rename(const String & oldFieldName, const String & newFieldN ame) status_t Message :: Rename(const String & oldFieldName, const String & newFieldN ame)
{ {
if (oldFieldName == newFieldName) return B_NO_ERROR; // nothing needs to be done in this case if (oldFieldName == newFieldName) return B_NO_ERROR; // nothing needs to be done in this case
MessageField temp; MessageField temp;
return (_entries.Remove(oldFieldName, temp) == B_NO_ERROR) ? _entries.Put(new FieldName, temp) : B_ERROR; return (_entries.Remove(oldFieldName, temp) == B_NO_ERROR) ? _entries.Put(new FieldName, temp) : B_DATA_NOT_FOUND;
} }
uint32 Message :: FlattenedSize() const uint32 Message :: FlattenedSize() const
{ {
uint32 sum = 3 * sizeof(uint32); // For the message header: 4 bytes for the protocol revision #, 4 bytes for the number-of-entries field, 4 bytes for what code uint32 sum = 3 * sizeof(uint32); // For the message header: 4 bytes for the protocol revision #, 4 bytes for the number-of-entries field, 4 bytes for what code
// For each flattenable field: 4 bytes for the name length, name data, 4 byte s for entry type code, 4 bytes for entry data length, entry data // For each flattenable field: 4 bytes for the name length, name data, 4 byte s for entry type code, 4 bytes for entry data length, entry data
for (HashtableIterator<String, MessageField> it(_entries, HTIT_FLAG_NOREGISTE R); it.HasData(); it++) for (HashtableIterator<String, MessageField> it(_entries, HTIT_FLAG_NOREGISTE R); it.HasData(); it++)
{ {
const MessageField & mf = it.GetValue(); const MessageField & mf = it.GetValue();
skipping to change at line 1358 skipping to change at line 1373
} }
status_t Message :: Unflatten(const uint8 * buffer, uint32 inputBufferBytes) status_t Message :: Unflatten(const uint8 * buffer, uint32 inputBufferBytes)
{ {
TCHECKPOINT; TCHECKPOINT;
Clear(true); Clear(true);
uint32 readOffset = 0; uint32 readOffset = 0;
status_t ret;
// Read and check protocol version number // Read and check protocol version number
uint32 networkByteOrder; uint32 networkByteOrder;
if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, sizeof (networkByteOrder)) != B_NO_ERROR) if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, sizeof (networkByteOrder)).IsError(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Couldn't read message protocol ver LogTime(MUSCLE_LOG_DEBUG, "Message %p: Couldn't read message protocol ver
sion! (inputBufferBytes=" UINT32_FORMAT_SPEC ")\n", this, inputBufferBytes); sion! (inputBufferBytes=" UINT32_FORMAT_SPEC ") ret=[%s]\n", this, inputBufferBy
return B_ERROR; tes, ret());
return ret;
} }
const uint32 messageProtocolVersion = B_LENDIAN_TO_HOST_INT32(networkByteOrde r); const uint32 messageProtocolVersion = B_LENDIAN_TO_HOST_INT32(networkByteOrde r);
if ((messageProtocolVersion < OLDEST_SUPPORTED_PROTOCOL_VERSION)||(messagePro tocolVersion > CURRENT_PROTOCOL_VERSION)) if ((messageProtocolVersion < OLDEST_SUPPORTED_PROTOCOL_VERSION)||(messagePro tocolVersion > CURRENT_PROTOCOL_VERSION))
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Unexpected message protocol versio n " UINT32_FORMAT_SPEC " (inputBufferBytes=" UINT32_FORMAT_SPEC ")\n", this, mes sageProtocolVersion, inputBufferBytes); LogTime(MUSCLE_LOG_DEBUG, "Message %p: Unexpected message protocol versio n " UINT32_FORMAT_SPEC " (inputBufferBytes=" UINT32_FORMAT_SPEC ")\n", this, mes sageProtocolVersion, inputBufferBytes);
return B_ERROR; return B_BAD_DATA;
} }
// Read 'what' code // Read 'what' code
if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, sizeof (networkByteOrder)) != B_NO_ERROR) if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, sizeof (networkByteOrder)).IsError(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Couldn't read what-code! (inputBuf LogTime(MUSCLE_LOG_DEBUG, "Message %p: Couldn't read what-code! (inputBuf
ferBytes=" UINT32_FORMAT_SPEC ")\n", this, inputBufferBytes); ferBytes=" UINT32_FORMAT_SPEC ") ret=[%s]\n", this, inputBufferBytes, ret());
return B_ERROR; return ret;
} }
what = B_LENDIAN_TO_HOST_INT32(networkByteOrder); what = B_LENDIAN_TO_HOST_INT32(networkByteOrder);
// Read number of entries // Read number of entries
if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, sizeof (networkByteOrder)) != B_NO_ERROR) if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, sizeof (networkByteOrder)).IsError(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Couldn't read number-of-entries! ( LogTime(MUSCLE_LOG_DEBUG, "Message %p: Couldn't read number-of-entries! (
inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC ")\n", this, inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC ") ret=[%s]\n
inputBufferBytes, what); ", this, inputBufferBytes, what, ret());
return B_ERROR; return ret;
} }
const uint32 numEntries = B_LENDIAN_TO_HOST_INT32(networkByteOrder); const uint32 numEntries = B_LENDIAN_TO_HOST_INT32(networkByteOrder);
const uint32 minBytesPerEntry = (sizeof(uint32)*3); // name-length + typec ode-length + payload-length const uint32 minBytesPerEntry = (sizeof(uint32)*3); // name-length + typec ode-length + payload-length
const uint32 maxPossibleEntries = inputBufferBytes / minBytesPerEntry; // ho w many fields might possibly fit in (inputBufferBytes) const uint32 maxPossibleEntries = inputBufferBytes / minBytesPerEntry; // ho w many fields might possibly fit in (inputBufferBytes)
if (numEntries > maxPossibleEntries) if (numEntries > maxPossibleEntries)
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Entries-count is larger than the i nput buffer could possibly represent! (inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " numEntries=" UINT32_FORMAT_SPEC ", maxPossibleEntrie s=" UINT32_FORMAT_SPEC ")\n", this, inputBufferBytes, what, numEntries, maxPossi bleEntries); LogTime(MUSCLE_LOG_DEBUG, "Message %p: Entries-count is larger than the i nput buffer could possibly represent! (inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " numEntries=" UINT32_FORMAT_SPEC ", maxPossibleEntrie s=" UINT32_FORMAT_SPEC ")\n", this, inputBufferBytes, what, numEntries, maxPossi bleEntries);
return B_ERROR; return B_BAD_DATA;
} }
if (_entries.EnsureSize(numEntries, true) != B_NO_ERROR) return B_ERROR;
if (_entries.EnsureSize(numEntries, true).IsError(ret)) return ret;
// Read entries // Read entries
for (uint32 i=0; i<numEntries; i++) for (uint32 i=0; i<numEntries; i++)
{ {
// Read entry name length // Read entry name length
if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, siz eof(networkByteOrder)) != B_NO_ERROR) if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, siz eof(networkByteOrder)).IsError(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Error reading entry name length LogTime(MUSCLE_LOG_DEBUG, "Message %p: Error reading entry name length
! (inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT ! (inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT
32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC ")\n", this, inputBufferBytes, what, i, nu 32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC ") ret=[%s]\n", this, inputBufferBytes, wh
mEntries); at, i, numEntries, ret());
return B_ERROR; return ret;
} }
const uint32 nameLength = B_LENDIAN_TO_HOST_INT32(networkByteOrder); const uint32 nameLength = B_LENDIAN_TO_HOST_INT32(networkByteOrder);
if (nameLength > inputBufferBytes-readOffset) if (nameLength > inputBufferBytes-readOffset)
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Entry name length too long! (in putBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT32_FO RMAT_SPEC "/" UINT32_FORMAT_SPEC " nameLength=" UINT32_FORMAT_SPEC "/" UINT32_FO RMAT_SPEC ")\n", this, inputBufferBytes, what, i, numEntries, nameLength, (uint3 2)(inputBufferBytes-readOffset)); LogTime(MUSCLE_LOG_DEBUG, "Message %p: Entry name length too long! (in putBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT32_FO RMAT_SPEC "/" UINT32_FORMAT_SPEC " nameLength=" UINT32_FORMAT_SPEC "/" UINT32_FO RMAT_SPEC ")\n", this, inputBufferBytes, what, i, numEntries, nameLength, (uint3 2)(inputBufferBytes-readOffset));
return B_ERROR; return B_BAD_DATA;
} }
// Read entry name // Read entry name
String entryName; String entryName;
if (entryName.Unflatten(&buffer[readOffset], nameLength) != B_NO_ERROR) if (entryName.Unflatten(&buffer[readOffset], nameLength).IsError(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Unable to unflatten entry name! LogTime(MUSCLE_LOG_DEBUG, "Message %p: Unable to unflatten entry name!
(inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT3 (inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT3
2_FORMAT_SPEC "/" UINT32_FORMAT_SPEC " nameLength=" UINT32_FORMAT_SPEC ")\n", th 2_FORMAT_SPEC "/" UINT32_FORMAT_SPEC " nameLength=" UINT32_FORMAT_SPEC ") ret=[%
is, inputBufferBytes, what, i, numEntries, nameLength); s]\n", this, inputBufferBytes, what, i, numEntries, nameLength, ret());
return B_ERROR; return ret;
} }
readOffset += nameLength; readOffset += nameLength;
// Read entry type code // Read entry type code
if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, siz eof(networkByteOrder)) != B_NO_ERROR) if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, siz eof(networkByteOrder)).IsError(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Unable to read entry type code! LogTime(MUSCLE_LOG_DEBUG, "Message %p: Unable to read entry type code!
(inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT3 (inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT3
2_FORMAT_SPEC "/" UINT32_FORMAT_SPEC " entryName=[%s])\n", this, inputBufferByte 2_FORMAT_SPEC "/" UINT32_FORMAT_SPEC " entryName=[%s] ret=[%s])\n", this, inputB
s, what, i, numEntries, entryName()); ufferBytes, what, i, numEntries, entryName(), ret());
return B_ERROR; return ret;
} }
const uint32 tc = B_LENDIAN_TO_HOST_INT32(networkByteOrder); const uint32 tc = B_LENDIAN_TO_HOST_INT32(networkByteOrder);
// Read entry data length // Read entry data length
if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, siz eof(networkByteOrder)) != B_NO_ERROR) if (ReadData(buffer, inputBufferBytes, &readOffset, &networkByteOrder, siz eof(networkByteOrder)).IsError(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Unable to read data length! (in LogTime(MUSCLE_LOG_DEBUG, "Message %p: Unable to read data length! (in
putBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT32_FO putBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT32_FO
RMAT_SPEC "/" UINT32_FORMAT_SPEC " tc=" UINT32_FORMAT_SPEC " entryName=[%s])\n", RMAT_SPEC "/" UINT32_FORMAT_SPEC " tc=" UINT32_FORMAT_SPEC " entryName=[%s]) ret
this, inputBufferBytes, what, i, numEntries, tc, entryName()); =[%s]\n", this, inputBufferBytes, what, i, numEntries, tc, entryName(), ret());
return B_ERROR; return ret;
} }
const uint32 eLength = B_LENDIAN_TO_HOST_INT32(networkByteOrder); const uint32 eLength = B_LENDIAN_TO_HOST_INT32(networkByteOrder);
if (eLength > inputBufferBytes-readOffset) if (eLength > inputBufferBytes-readOffset)
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Data length is too long! (input BufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT32_FORMA T_SPEC "/" UINT32_FORMAT_SPEC " tc=" UINT32_FORMAT_SPEC " eLength=" UINT32_FORMA T_SPEC "/" UINT32_FORMAT_SPEC " entryName=[%s])\n", this, inputBufferBytes, what , i, numEntries, tc, eLength, (uint32)(inputBufferBytes-readOffset), entryName() ); LogTime(MUSCLE_LOG_DEBUG, "Message %p: Data length is too long! (input BufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT32_FORMA T_SPEC "/" UINT32_FORMAT_SPEC " tc=" UINT32_FORMAT_SPEC " eLength=" UINT32_FORMA T_SPEC "/" UINT32_FORMAT_SPEC " entryName=[%s])\n", this, inputBufferBytes, what , i, numEntries, tc, eLength, (uint32)(inputBufferBytes-readOffset), entryName() );
return B_ERROR; return B_BAD_DATA;
} }
MessageField * nextEntry = GetOrCreateMessageField(entryName, tc); MessageField * nextEntry = GetOrCreateMessageField(entryName, tc);
if (nextEntry == NULL) if (nextEntry == NULL)
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Unable to create data field obj ect! (inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC " tc=" UINT32_FORMAT_SPEC " entryName= [%s])\n", this, inputBufferBytes, what, i, numEntries, tc, entryName()); LogTime(MUSCLE_LOG_DEBUG, "Message %p: Unable to create data field obj ect! (inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i=" UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC " tc=" UINT32_FORMAT_SPEC " entryName= [%s])\n", this, inputBufferBytes, what, i, numEntries, tc, entryName());
return B_ERROR; return B_BAD_DATA;
} }
if (nextEntry->Unflatten(&buffer[readOffset], eLength) != B_NO_ERROR) if (nextEntry->Unflatten(&buffer[readOffset], eLength).IsError(ret))
{ {
LogTime(MUSCLE_LOG_DEBUG, "Message %p: Unable to unflatten data field object! (inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i =" UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC " tc=" UINT32_FORMAT_SPEC " entryNa me=[%s] eLength=" UINT32_FORMAT_SPEC ")\n", this, inputBufferBytes, what, i, num Entries, tc, entryName(), eLength); LogTime(MUSCLE_LOG_DEBUG, "Message %p: Unable to unflatten data field object! (inputBufferBytes=" UINT32_FORMAT_SPEC ", what=" UINT32_FORMAT_SPEC " i =" UINT32_FORMAT_SPEC "/" UINT32_FORMAT_SPEC " tc=" UINT32_FORMAT_SPEC " entryNa me=[%s] eLength=" UINT32_FORMAT_SPEC ") ret=[%s]\n", this, inputBufferBytes, wha t, i, numEntries, tc, entryName(), eLength, ret());
Clear(); // fix for occasional crash bug; we were deleting nextEntry h ere, *and* in the destructor! Clear(); // fix for occasional crash bug; we were deleting nextEntry h ere, *and* in the destructor!
return B_ERROR; return ret;
} }
readOffset += eLength; readOffset += eLength;
} }
return B_NO_ERROR; return B_NO_ERROR;
} }
status_t Message :: AddFlatAux(const String & fieldName, const FlatCountableRef & ref, uint32 tc, bool prepend) status_t Message :: AddFlatAux(const String & fieldName, const FlatCountableRef & ref, uint32 tc, bool prepend)
{ {
MessageField * field = ref() ? GetOrCreateMessageField(fieldName, tc) : NULL; MessageField * field = ref() ? GetOrCreateMessageField(fieldName, tc) : NULL;
return field ? (prepend ? field->PrependDataItem(&ref, sizeof(ref)) : field-> AddDataItem(&ref, sizeof(ref))) : B_ERROR; return field ? (prepend ? field->PrependDataItem(&ref, sizeof(ref)) : field-> AddDataItem(&ref, sizeof(ref))) : B_TYPE_MISMATCH;
} }
status_t Message :: AddString(const String & fieldName, const String & val) status_t Message :: AddString(const String & fieldName, const String & val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_STRING_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_STRING_TYPE);
return mf ? mf->AddDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->AddDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: AddInt8(const String & fieldName, int8 val) status_t Message :: AddInt8(const String & fieldName, int8 val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_INT8_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_INT8_TYPE);
return mf ? mf->AddDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->AddDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: AddInt16(const String & fieldName, int16 val) status_t Message :: AddInt16(const String & fieldName, int16 val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_INT16_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_INT16_TYPE);
return mf ? mf->AddDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->AddDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: AddInt32(const String & fieldName, int32 val) status_t Message :: AddInt32(const String & fieldName, int32 val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_INT32_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_INT32_TYPE);
return mf ? mf->AddDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->AddDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: AddInt64(const String & fieldName, int64 val) status_t Message :: AddInt64(const String & fieldName, int64 val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_INT64_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_INT64_TYPE);
return mf ? mf->AddDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->AddDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: AddBool(const String & fieldName, bool val) status_t Message :: AddBool(const String & fieldName, bool val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_BOOL_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_BOOL_TYPE);
status_t ret = mf ? mf->AddDataItem(&val, sizeof(val)) : B_ERROR; status_t ret = mf ? mf->AddDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
return ret; return ret;
} }
status_t Message :: AddFloat(const String & fieldName, float val) status_t Message :: AddFloat(const String & fieldName, float val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_FLOAT_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_FLOAT_TYPE);
return mf ? mf->AddDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->AddDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: AddDouble(const String & fieldName, double val) status_t Message :: AddDouble(const String & fieldName, double val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_DOUBLE_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_DOUBLE_TYPE);
return mf ? mf->AddDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->AddDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: AddPointer(const String & fieldName, const void * ptr) status_t Message :: AddPointer(const String & fieldName, const void * ptr)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_POINTER_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_POINTER_TYPE);
return mf ? mf->AddDataItem(&ptr, sizeof(ptr)) : B_ERROR; return mf ? mf->AddDataItem(&ptr, sizeof(ptr)) : B_TYPE_MISMATCH;
} }
status_t Message :: AddPoint(const String & fieldName, const Point & point) status_t Message :: AddPoint(const String & fieldName, const Point & point)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_POINT_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_POINT_TYPE);
return mf ? mf->AddDataItem(&point, sizeof(point)) : B_ERROR; return mf ? mf->AddDataItem(&point, sizeof(point)) : B_TYPE_MISMATCH;
} }
status_t Message :: AddRect(const String & fieldName, const Rect & rect) status_t Message :: AddRect(const String & fieldName, const Rect & rect)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_RECT_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_RECT_TYPE);
return mf ? mf->AddDataItem(&rect, sizeof(rect)) : B_ERROR; return mf ? mf->AddDataItem(&rect, sizeof(rect)) : B_TYPE_MISMATCH;
} }
status_t Message :: AddTag(const String & fieldName, const RefCountableRef & tag ) status_t Message :: AddTag(const String & fieldName, const RefCountableRef & tag )
{ {
if (tag() == NULL) return B_ERROR; if (tag() == NULL) return B_BAD_ARGUMENT;
MessageField * mf = GetOrCreateMessageField(fieldName, B_TAG_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_TAG_TYPE);
return mf ? mf->AddDataItem(&tag, sizeof(tag)) : B_ERROR; return mf ? mf->AddDataItem(&tag, sizeof(tag)) : B_TYPE_MISMATCH;
} }
status_t Message :: AddMessage(const String & fieldName, const MessageRef & ref) status_t Message :: AddMessage(const String & fieldName, const MessageRef & ref)
{ {
if (ref() == NULL) return B_ERROR; if (ref() == NULL) return B_BAD_ARGUMENT;
MessageField * mf = GetOrCreateMessageField(fieldName, B_MESSAGE_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_MESSAGE_TYPE);
return (mf) ? mf->AddDataItem(&ref, sizeof(ref)) : B_ERROR; return (mf) ? mf->AddDataItem(&ref, sizeof(ref)) : B_TYPE_MISMATCH;
} }
status_t Message :: AddFlat(const String & fieldName, const FlatCountableRef & r ef) status_t Message :: AddFlat(const String & fieldName, const FlatCountableRef & r ef)
{ {
FlatCountable * fc = ref(); FlatCountable * fc = ref();
if (fc) if (fc)
{ {
const uint32 tc = fc->TypeCode(); const uint32 tc = fc->TypeCode();
switch(tc) switch(tc)
{ {
case B_STRING_TYPE: return B_ERROR; // sorry, can't do that (Strings case B_STRING_TYPE: return B_TYPE_MISMATCH; // sorry, can't do that (
aren't FlatCountables) Strings aren't FlatCountables)
case B_POINT_TYPE: return B_ERROR; // sorry, can't do that (Points a case B_POINT_TYPE: return B_TYPE_MISMATCH; // sorry, can't do that (
ren't FlatCountables) Points aren't FlatCountables)
case B_RECT_TYPE: return B_ERROR; // sorry, can't do that (Rects ar case B_RECT_TYPE: return B_TYPE_MISMATCH; // sorry, can't do that (
en't FlatCountables) Rects aren't FlatCountables)
case B_MESSAGE_TYPE: return AddMessage(fieldName, MessageRef(ref.GetRef CountableRef(), true)); case B_MESSAGE_TYPE: return AddMessage(fieldName, MessageRef(ref.GetRef CountableRef(), true));
default: return AddFlatAux(fieldName, ref, tc, false); default: return AddFlatAux(fieldName, ref, tc, false);
} }
} }
return B_ERROR; return B_BAD_ARGUMENT;
} }
uint32 Message :: GetElementSize(uint32 type) uint32 Message :: GetElementSize(uint32 type)
{ {
switch(type) switch(type)
{ {
case B_BOOL_TYPE: return sizeof(bool); case B_BOOL_TYPE: return sizeof(bool);
case B_DOUBLE_TYPE: return sizeof(double); case B_DOUBLE_TYPE: return sizeof(double);
case B_POINTER_TYPE: return sizeof(void *); case B_POINTER_TYPE: return sizeof(void *);
case B_POINT_TYPE: return sizeof(Point); case B_POINT_TYPE: return sizeof(Point);
skipping to change at line 1591 skipping to change at line 1609
case B_INT16_TYPE: return sizeof(int16); case B_INT16_TYPE: return sizeof(int16);
case B_INT8_TYPE: return sizeof(int8); case B_INT8_TYPE: return sizeof(int8);
case B_MESSAGE_TYPE: return sizeof(MessageRef); case B_MESSAGE_TYPE: return sizeof(MessageRef);
case B_STRING_TYPE: return sizeof(String); case B_STRING_TYPE: return sizeof(String);
default: return 0; default: return 0;
} }
} }
status_t Message :: AddDataAux(const String & fieldName, const void * data, uint 32 numBytes, uint32 tc, bool prepend) status_t Message :: AddDataAux(const String & fieldName, const void * data, uint 32 numBytes, uint32 tc, bool prepend)
{ {
if (numBytes == 0) return B_ERROR; // can't add 0 bytes, that's silly if (numBytes == 0) return B_BAD_ARGUMENT; // can't add 0 bytes, that's sill y
if (tc == B_STRING_TYPE) if (tc == B_STRING_TYPE)
{ {
String temp((const char *)data); // kept separate to avoid BeOS gcc optim izer bug (otherwise -O3 crashes here) String temp((const char *)data); // kept separate to avoid BeOS gcc optim izer bug (otherwise -O3 crashes here)
return prepend ? PrependString(fieldName, temp) : AddString(fieldName, tem p); return prepend ? PrependString(fieldName, temp) : AddString(fieldName, tem p);
} }
// for primitive types, we do this: // for primitive types, we do this:
bool isVariableSize = false; bool isVariableSize = false;
uint32 elementSize = GetElementSize(tc); uint32 elementSize = GetElementSize(tc);
if (elementSize == 0) if (elementSize == 0)
{ {
// zero indicates a variable-sized data item; we will use a ByteBuffer to hold it. // zero indicates a variable-sized data item; we will use a ByteBuffer to hold it.
isVariableSize = true; isVariableSize = true;
elementSize = numBytes; elementSize = numBytes;
if (elementSize == 0) return B_ERROR; if (elementSize == 0) return B_TYPE_MISMATCH;
} }
if (numBytes % elementSize) return B_ERROR; // Can't add half an element, si lly! if (numBytes % elementSize) return B_BAD_ARGUMENT; // Can't add half an elem ent, silly!
MessageField * mf = GetOrCreateMessageField(fieldName, tc); MessageField * mf = GetOrCreateMessageField(fieldName, tc);
if (mf == NULL) return B_ERROR; if (mf == NULL) return B_TYPE_MISMATCH;
status_t ret;
const uint32 numElements = numBytes/elementSize; const uint32 numElements = numBytes/elementSize;
const uint8 * dataBuf = (const uint8 *) data; const uint8 * dataBuf = (const uint8 *) data;
for (uint32 i=0; i<numElements; i++) for (uint32 i=0; i<numElements; i++)
{ {
FlatCountableRef fcRef; FlatCountableRef fcRef;
const void * dataToAdd = dataBuf ? &dataBuf[i*elementSize] : NULL; const void * dataToAdd = dataBuf ? &dataBuf[i*elementSize] : NULL;
uint32 addSize = elementSize; uint32 addSize = elementSize;
if (isVariableSize) if (isVariableSize)
{ {
ByteBufferRef bufRef = GetByteBufferFromPool(elementSize, (const uint8 *)dataToAdd); ByteBufferRef bufRef = GetByteBufferFromPool(elementSize, (const uint8 *)dataToAdd);
if (bufRef() == NULL) {WARN_OUT_OF_MEMORY; return B_ERROR;} if (bufRef() == NULL) RETURN_OUT_OF_MEMORY;
fcRef.SetFromRefCountableRef(bufRef.GetRefCountableRef()); fcRef.SetFromRefCountableRef(bufRef.GetRefCountableRef());
dataToAdd = &fcRef; dataToAdd = &fcRef;
addSize = sizeof(fcRef); addSize = sizeof(fcRef);
} }
if ((prepend ? mf->PrependDataItem(dataToAdd, addSize) : mf->AddDataItem(d ataToAdd, addSize)) != B_NO_ERROR) return B_ERROR; if ((prepend ? mf->PrependDataItem(dataToAdd, addSize) : mf->AddDataItem(d ataToAdd, addSize)).IsError(ret)) return ret;
} }
return B_NO_ERROR; return B_NO_ERROR;
} }
void * Message :: GetPointerToNormalizedFieldData(const String & fieldName, uint 32 * retNumItems, uint32 typeCode) void * Message :: GetPointerToNormalizedFieldData(const String & fieldName, uint 32 * retNumItems, uint32 typeCode)
{ {
MessageField * e = GetMessageField(fieldName, typeCode); MessageField * e = GetMessageField(fieldName, typeCode);
if (e) if (e)
{ {
e->Normalize(); e->Normalize();
skipping to change at line 1653 skipping to change at line 1672
if (retNumItems) *retNumItems = e->GetNumItems(); if (retNumItems) *retNumItems = e->GetNumItems();
return const_cast<void *>(ptr); return const_cast<void *>(ptr);
} }
} }
return NULL; return NULL;
} }
status_t Message :: EnsureFieldIsPrivate(const String & fieldName) status_t Message :: EnsureFieldIsPrivate(const String & fieldName)
{ {
MessageField * mf = GetMessageField(fieldName, B_ANY_TYPE); MessageField * mf = GetMessageField(fieldName, B_ANY_TYPE);
return mf ? mf->EnsurePrivate() : B_ERROR; return mf ? mf->EnsurePrivate() : B_DATA_NOT_FOUND;
} }
status_t Message :: RemoveData(const String & fieldName, uint32 index) status_t Message :: RemoveData(const String & fieldName, uint32 index)
{ {
MessageField * mf = GetMessageField(fieldName, B_ANY_TYPE); MessageField * mf = GetMessageField(fieldName, B_ANY_TYPE);
if (mf) if (mf)
{ {
const status_t ret = mf->RemoveDataItem(index); const status_t ret = mf->RemoveDataItem(index);
return mf->IsEmpty() ? RemoveName(fieldName) : ret; return mf->IsEmpty() ? RemoveName(fieldName) : ret;
} }
else return B_ERROR; else return B_DATA_NOT_FOUND;
} }
status_t Message :: FindString(const String & fieldName, uint32 index, const cha r * & setMe) const status_t Message :: FindString(const String & fieldName, uint32 index, const cha r * & setMe) const
{ {
const MessageField * mf = GetMessageField(fieldName, B_STRING_TYPE); const MessageField * mf = GetMessageField(fieldName, B_STRING_TYPE);
if ((mf)&&(index < mf->GetNumItems())) if ((mf)&&(index < mf->GetNumItems()))
{ {
setMe = mf->GetItemAtAsString(index)(); setMe = mf->GetItemAtAsString(index)();
return B_NO_ERROR; return B_NO_ERROR;
} }
else return B_ERROR; else return B_DATA_NOT_FOUND;
} }
status_t Message :: FindString(const String & fieldName, uint32 index, const Str ing ** setMe) const status_t Message :: FindString(const String & fieldName, uint32 index, const Str ing ** setMe) const
{ {
const MessageField * mf = GetMessageField(fieldName, B_STRING_TYPE); const MessageField * mf = GetMessageField(fieldName, B_STRING_TYPE);
if ((mf)&&(index < mf->GetNumItems())) if ((mf)&&(index < mf->GetNumItems()))
{ {
*setMe = &mf->GetItemAtAsString(index); *setMe = &mf->GetItemAtAsString(index);
return B_NO_ERROR; return B_NO_ERROR;
} }
else return B_ERROR; else return B_DATA_NOT_FOUND;
} }
status_t Message :: FindString(const String & fieldName, uint32 index, String & str) const status_t Message :: FindString(const String & fieldName, uint32 index, String & str) const
{ {
const MessageField * mf = GetMessageField(fieldName, B_STRING_TYPE); const MessageField * mf = GetMessageField(fieldName, B_STRING_TYPE);
if ((mf)&&(index < mf->GetNumItems())) if ((mf)&&(index < mf->GetNumItems()))
{ {
str = mf->GetItemAtAsString(index); str = mf->GetItemAtAsString(index);
return B_NO_ERROR; return B_NO_ERROR;
} }
else return B_ERROR; else return B_DATA_NOT_FOUND;
} }
const uint8 * Message :: FindFlatAux(const MessageField * mf, uint32 index, uint 32 & retNumBytes, const FlatCountable ** optRetFCPtr) const const uint8 * Message :: FindFlatAux(const MessageField * mf, uint32 index, uint 32 & retNumBytes, const FlatCountable ** optRetFCPtr) const
{ {
if (optRetFCPtr) *optRetFCPtr = NULL; if (optRetFCPtr) *optRetFCPtr = NULL;
if (index >= mf->GetNumItems()) return NULL; if (index >= mf->GetNumItems()) return NULL;
RefCountableRef rcRef = mf->GetItemAtAsRefCountableRef(index); RefCountableRef rcRef = mf->GetItemAtAsRefCountableRef(index);
const ByteBuffer * bb = dynamic_cast<const ByteBuffer *>(rcRef()); const ByteBuffer * bb = dynamic_cast<const ByteBuffer *>(rcRef());
skipping to change at line 1737 skipping to change at line 1756
retNumBytes = mf->GetItemSize(index); retNumBytes = mf->GetItemSize(index);
return (const uint8 *)data; return (const uint8 *)data;
} }
else return NULL; else return NULL;
} }
status_t Message :: FindFlat(const String & fieldName, uint32 index, FlatCountab leRef & ref) const status_t Message :: FindFlat(const String & fieldName, uint32 index, FlatCountab leRef & ref) const
{ {
TCHECKPOINT; TCHECKPOINT;
const MessageField * field = GetMessageField(fieldName, B_ANY_TYPE); const MessageField * mf = GetMessageField(fieldName, B_ANY_TYPE);
if ((field)&&(index < field->GetNumItems())) if ((mf)&&(index < mf->GetNumItems()))
{ {
RefCountableRef rcRef = field->GetItemAtAsRefCountableRef(index); RefCountableRef rcRef = mf->GetItemAtAsRefCountableRef(index);
ref.SetFromRefCountableRef(rcRef); ref.SetFromRefCountableRef(rcRef);
if (ref()) return B_NO_ERROR; return ref() ? B_NO_ERROR : B_TYPE_MISMATCH;
} }
return B_ERROR; else return B_DATA_NOT_FOUND;
} }
status_t Message :: FindData(const String & fieldName, uint32 tc, uint32 index, const void ** data, uint32 * setSize) const status_t Message :: FindData(const String & fieldName, uint32 tc, uint32 index, const void ** data, uint32 * setSize) const
{ {
TCHECKPOINT; TCHECKPOINT;
const MessageField * field = GetMessageField(fieldName, tc); const MessageField * field = GetMessageField(fieldName, tc);
if ((field)&&(field->FindDataItem(index, data) == B_NO_ERROR)) if (field == NULL) return B_DATA_NOT_FOUND;
status_t ret;
if (field->FindDataItem(index, data).IsOK(ret))
{ {
switch(tc) switch(tc)
{ {
case B_STRING_TYPE: case B_STRING_TYPE:
{ {
const String * str = (const String *) (*data); const String * str = (const String *) (*data);
*data = str->Cstr(); *data = str->Cstr();
if (setSize) *setSize = str->FlattenedSize(); if (setSize) *setSize = str->FlattenedSize();
} }
break; break;
case B_ANY_TYPE: case B_ANY_TYPE:
return (field->TypeCode() == B_ANY_TYPE) ? B_ERROR : FindData(fieldN ame, field->TypeCode(), 0, data, setSize); return (field->TypeCode() == B_ANY_TYPE) ? B_BAD_OBJECT : FindData(f ieldName, field->TypeCode(), 0, data, setSize);
break; break;
default: default:
{ {
const uint32 es = GetElementSize(tc); const uint32 es = GetElementSize(tc);
if (es > 0) if (es > 0)
{ {
if (setSize) *setSize = es; if (setSize) *setSize = es;
} }
else else
skipping to change at line 1790 skipping to change at line 1812
if (buf) if (buf)
{ {
const void * b = buf->GetBuffer(); const void * b = buf->GetBuffer();
if (b) if (b)
{ {
*data = b; *data = b;
if (setSize) *setSize = buf->GetNumBytes(); if (setSize) *setSize = buf->GetNumBytes();
return B_NO_ERROR; return B_NO_ERROR;
} }
} }
return B_ERROR; return B_TYPE_MISMATCH;
} }
} }
break; break;
} }
return B_NO_ERROR; return B_NO_ERROR;
} }
else return B_ERROR; else return ret;
} }
status_t Message :: FindDataItemAux(const String & fieldName, uint32 index, uint 32 tc, void * setValue, uint32 valueSize) const status_t Message :: FindDataItemAux(const String & fieldName, uint32 index, uint 32 tc, void * setValue, uint32 valueSize) const
{ {
const MessageField * field = GetMessageField(fieldName, tc); const MessageField * field = GetMessageField(fieldName, tc);
if (field == NULL) return B_ERROR; if (field == NULL) return B_DATA_NOT_FOUND;
const void * addressOfValue; const void * addressOfValue;
const status_t ret = field->FindDataItem(index, &addressOfValue); const status_t ret = field->FindDataItem(index, &addressOfValue);
if (ret != B_NO_ERROR) return ret; if (ret != B_NO_ERROR) return ret;
memcpy(setValue, addressOfValue, valueSize); memcpy(setValue, addressOfValue, valueSize);
return B_NO_ERROR; return B_NO_ERROR;
} }
status_t Message :: FindPoint(const String & fieldName, uint32 index, Point & po int) const status_t Message :: FindPoint(const String & fieldName, uint32 index, Point & po int) const
{ {
const MessageField * field = GetMessageField(fieldName, B_POINT_TYPE); const MessageField * mf = GetMessageField(fieldName, B_POINT_TYPE);
if ((field == NULL)||(index >= field->GetNumItems())) return B_ERROR; if ((mf)&&(index < mf->GetNumItems()))
point = field->GetItemAtAsPoint(index); {
return B_NO_ERROR; point = mf->GetItemAtAsPoint(index);
return B_NO_ERROR;
}
else return B_DATA_NOT_FOUND;
} }
status_t Message :: FindRect(const String & fieldName, uint32 index, Rect & rect ) const status_t Message :: FindRect(const String & fieldName, uint32 index, Rect & rect ) const
{ {
const MessageField * field = GetMessageField(fieldName, B_RECT_TYPE); const MessageField * mf = GetMessageField(fieldName, B_RECT_TYPE);
if ((field == NULL)||(index >= field->GetNumItems())) return B_ERROR; if ((mf)&&(index < mf->GetNumItems()))
rect = field->GetItemAtAsRect(index); {
return B_NO_ERROR; rect = mf->GetItemAtAsRect(index);
return B_NO_ERROR;
}
else return B_DATA_NOT_FOUND;
} }
status_t Message :: FindTag(const String & fieldName, uint32 index, RefCountable Ref & tag) const status_t Message :: FindTag(const String & fieldName, uint32 index, RefCountable Ref & tag) const
{ {
const MessageField * field = GetMessageField(fieldName, B_TAG_TYPE); const MessageField * mf = GetMessageField(fieldName, B_TAG_TYPE);
if ((field == NULL)||(index >= field->GetNumItems())) return B_ERROR; if ((mf)&&(index < mf->GetNumItems()))
tag = field->GetItemAtAsRefCountableRef(index); {
return B_NO_ERROR; tag = mf->GetItemAtAsRefCountableRef(index);
return B_NO_ERROR;
}
else return B_DATA_NOT_FOUND;
} }
status_t Message :: FindMessage(const String & fieldName, uint32 index, Message & msg) const status_t Message :: FindMessage(const String & fieldName, uint32 index, Message & msg) const
{ {
status_t ret;
MessageRef msgRef; MessageRef msgRef;
if (FindMessage(fieldName, index, msgRef) == B_NO_ERROR) if (FindMessage(fieldName, index, msgRef).IsOK(ret))
{ {
const Message * m = msgRef(); const Message * m = msgRef();
if (m) if (m)
{ {
msg = *m; msg = *m;
return B_NO_ERROR; return B_NO_ERROR;
} }
else return B_BAD_OBJECT;
} }
return B_ERROR; else return ret;
} }
status_t Message :: FindMessage(const String & fieldName, uint32 index, MessageR ef & ref) const status_t Message :: FindMessage(const String & fieldName, uint32 index, MessageR ef & ref) const
{ {
const MessageField * field = GetMessageField(fieldName, B_MESSAGE_TYPE); const MessageField * mf = GetMessageField(fieldName, B_MESSAGE_TYPE);
if ((field == NULL)||(index >= field->GetNumItems())) return B_ERROR; if ((mf)&&(index < mf->GetNumItems()))
RefCountableRef rcRef = field->GetItemAtAsRefCountableRef(index);
if (rcRef())
{ {
ref.SetFromRefCountableRef(rcRef); RefCountableRef rcRef = mf->GetItemAtAsRefCountableRef(index);
return ref() ? B_NO_ERROR : B_ERROR; if (rcRef())
{
ref.SetFromRefCountableRef(rcRef);
return ref() ? B_NO_ERROR : B_TYPE_MISMATCH;
}
else return B_BAD_OBJECT;
} }
else return B_ERROR; else return B_DATA_NOT_FOUND;
} }
status_t Message :: FindDataPointer(const String & fieldName, uint32 tc, uint32 index, void ** data, uint32 * setSize) const status_t Message :: FindDataPointer(const String & fieldName, uint32 tc, uint32 index, void ** data, uint32 * setSize) const
{ {
const void * dataLoc; const void * dataLoc;
status_t ret = FindData(fieldName, tc, index, &dataLoc, setSize); status_t ret;
if (ret == B_NO_ERROR) if (FindData(fieldName, tc, index, &dataLoc, setSize).IsOK(ret))
{ {
*data = (void *) dataLoc; // breaks const correctness, but oh well *data = (void *) dataLoc; // breaks const correctness, but oh well
return B_NO_ERROR; return B_NO_ERROR;
} }
else return B_ERROR; else return ret;
} }
status_t Message :: ReplaceString(bool okayToAdd, const String & fieldName, uint 32 index, const String & string) status_t Message :: ReplaceString(bool okayToAdd, const String & fieldName, uint 32 index, const String & string)
{ {
MessageField * field = GetMessageField(fieldName, B_STRING_TYPE); MessageField * field = GetMessageField(fieldName, B_STRING_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddString(fieldName, string); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddString(fieldName, string);
return field ? field->ReplaceDataItem(index, &string, sizeof(string)) : B_ERR OR; return field ? field->ReplaceDataItem(index, &string, sizeof(string)) : B_DAT A_NOT_FOUND;
} }
status_t Message :: ReplaceFlatAux(bool okayToAdd, const String & fieldName, uin t32 index, const ByteBufferRef & bufRef, uint32 tc) status_t Message :: ReplaceFlatAux(bool okayToAdd, const String & fieldName, uin t32 index, const ByteBufferRef & bufRef, uint32 tc)
{ {
FlatCountableRef fcRef; fcRef.SetFromRefCountableRefUnchecked(bufRef.GetRefCo untableRef()); FlatCountableRef fcRef; fcRef.SetFromRefCountableRefUnchecked(bufRef.GetRefCo untableRef());
return ReplaceDataAux(okayToAdd, fieldName, index, &fcRef, sizeof(fcRef), tc) ; return ReplaceDataAux(okayToAdd, fieldName, index, &fcRef, sizeof(fcRef), tc) ;
} }
status_t Message :: ReplaceDataAux(bool okayToAdd, const String & fieldName, uin t32 index, void * dataBuf, uint32 bufSize, uint32 tc) status_t Message :: ReplaceDataAux(bool okayToAdd, const String & fieldName, uin t32 index, void * dataBuf, uint32 bufSize, uint32 tc)
{ {
MessageField * field = GetMessageField(fieldName, tc); MessageField * field = GetMessageField(fieldName, tc);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddDataAux(fieldName, dataBuf, bufSize, tc, false); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddDataAux(fieldName, dataBuf, bufSize, tc, false);
return field ? field->ReplaceDataItem(index, dataBuf, bufSize) : B_ERROR; return field ? field->ReplaceDataItem(index, dataBuf, bufSize) : B_DATA_NOT_F OUND;
} }
status_t Message :: ReplaceInt8(bool okayToAdd, const String & fieldName, uint32 index, int8 val) status_t Message :: ReplaceInt8(bool okayToAdd, const String & fieldName, uint32 index, int8 val)
{ {
MessageField * field = GetMessageField(fieldName, B_INT8_TYPE); MessageField * field = GetMessageField(fieldName, B_INT8_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddInt8(fieldName, val); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddInt8(fieldName, val);
return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_ERROR; return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_DATA_NOT_ FOUND;
} }
status_t Message :: ReplaceInt16(bool okayToAdd, const String & fieldName, uint3 2 index, int16 val) status_t Message :: ReplaceInt16(bool okayToAdd, const String & fieldName, uint3 2 index, int16 val)
{ {
MessageField * field = GetMessageField(fieldName, B_INT16_TYPE); MessageField * field = GetMessageField(fieldName, B_INT16_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddInt16(fieldName, val); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddInt16(fieldName, val);
return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_ERROR; return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_DATA_NOT_ FOUND;
} }
status_t Message :: ReplaceInt32(bool okayToAdd, const String & fieldName, uint3 2 index, int32 val) status_t Message :: ReplaceInt32(bool okayToAdd, const String & fieldName, uint3 2 index, int32 val)
{ {
MessageField * field = GetMessageField(fieldName, B_INT32_TYPE); MessageField * field = GetMessageField(fieldName, B_INT32_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddInt32(fieldName, val); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddInt32(fieldName, val);
return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_ERROR; return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_DATA_NOT_ FOUND;
} }
status_t Message :: ReplaceInt64(bool okayToAdd, const String & fieldName, uint3 2 index, int64 val) status_t Message :: ReplaceInt64(bool okayToAdd, const String & fieldName, uint3 2 index, int64 val)
{ {
MessageField * field = GetMessageField(fieldName, B_INT64_TYPE); MessageField * field = GetMessageField(fieldName, B_INT64_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddInt64(fieldName, val); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddInt64(fieldName, val);
return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_ERROR; return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_DATA_NOT_ FOUND;
} }
status_t Message :: ReplaceBool(bool okayToAdd, const String & fieldName, uint32 index, bool val) status_t Message :: ReplaceBool(bool okayToAdd, const String & fieldName, uint32 index, bool val)
{ {
MessageField * field = GetMessageField(fieldName, B_BOOL_TYPE); MessageField * field = GetMessageField(fieldName, B_BOOL_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddBool(fieldName, val); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddBool(fieldName, val);
return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_ERROR; return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_DATA_NOT_ FOUND;
} }
status_t Message :: ReplaceFloat(bool okayToAdd, const String & fieldName, uint3 2 index, float val) status_t Message :: ReplaceFloat(bool okayToAdd, const String & fieldName, uint3 2 index, float val)
{ {
MessageField * field = GetMessageField(fieldName, B_FLOAT_TYPE); MessageField * field = GetMessageField(fieldName, B_FLOAT_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddFloat(fieldName, val); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddFloat(fieldName, val);
return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_ERROR; return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_DATA_NOT_ FOUND;
} }
status_t Message :: ReplaceDouble(bool okayToAdd, const String & fieldName, uint 32 index, double val) status_t Message :: ReplaceDouble(bool okayToAdd, const String & fieldName, uint 32 index, double val)
{ {
MessageField * field = GetMessageField(fieldName, B_DOUBLE_TYPE); MessageField * field = GetMessageField(fieldName, B_DOUBLE_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddDouble(fieldName, val); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddDouble(fieldName, val);
return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_ERROR; return field ? field->ReplaceDataItem(index, &val, sizeof(val)) : B_DATA_NOT_ FOUND;
} }
status_t Message :: ReplacePointer(bool okayToAdd, const String & fieldName, uin t32 index, const void * ptr) status_t Message :: ReplacePointer(bool okayToAdd, const String & fieldName, uin t32 index, const void * ptr)
{ {
MessageField * field = GetMessageField(fieldName, B_POINTER_TYPE); MessageField * field = GetMessageField(fieldName, B_POINTER_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddPointer(fieldName, ptr); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddPointer(fieldName, ptr);
return field ? field->ReplaceDataItem(index, &ptr, sizeof(ptr)) : B_ERROR; return field ? field->ReplaceDataItem(index, &ptr, sizeof(ptr)) : B_DATA_NOT_ FOUND;
} }
status_t Message :: ReplacePoint(bool okayToAdd, const String & fieldName, uint3 2 index, const Point &point) status_t Message :: ReplacePoint(bool okayToAdd, const String & fieldName, uint3 2 index, const Point &point)
{ {
MessageField * field = GetMessageField(fieldName, B_POINT_TYPE); MessageField * field = GetMessageField(fieldName, B_POINT_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddPoint(fieldName, point); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddPoint(fieldName, point);
return field ? field->ReplaceDataItem(index, &point, sizeof(point)) : B_ERROR ; return field ? field->ReplaceDataItem(index, &point, sizeof(point)) : B_DATA_ NOT_FOUND;
} }
status_t Message :: ReplaceRect(bool okayToAdd, const String & fieldName, uint32 index, const Rect &rect) status_t Message :: ReplaceRect(bool okayToAdd, const String & fieldName, uint32 index, const Rect &rect)
{ {
MessageField * field = GetMessageField(fieldName, B_RECT_TYPE); MessageField * field = GetMessageField(fieldName, B_RECT_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddRect(fieldName, rect); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddRect(fieldName, rect);
return field ? field->ReplaceDataItem(index, &rect, sizeof(rect)) : B_ERROR; return field ? field->ReplaceDataItem(index, &rect, sizeof(rect)) : B_DATA_NO T_FOUND;
} }
status_t Message :: ReplaceTag(bool okayToAdd, const String & fieldName, uint32 index, const RefCountableRef & tag) status_t Message :: ReplaceTag(bool okayToAdd, const String & fieldName, uint32 index, const RefCountableRef & tag)
{ {
if (tag() == NULL) return B_ERROR; if (tag() == NULL) return B_BAD_ARGUMENT;
MessageField * field = GetMessageField(fieldName, B_TAG_TYPE); MessageField * field = GetMessageField(fieldName, B_TAG_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddTag(fieldName, tag); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddTag(fieldName, tag);
return field ? field->ReplaceDataItem(index, &tag, sizeof(tag)) : B_ERROR; return field ? field->ReplaceDataItem(index, &tag, sizeof(tag)) : B_DATA_NOT_ FOUND;
} }
status_t Message :: ReplaceMessage(bool okayToAdd, const String & fieldName, uin t32 index, const MessageRef & msgRef) status_t Message :: ReplaceMessage(bool okayToAdd, const String & fieldName, uin t32 index, const MessageRef & msgRef)
{ {
if (msgRef() == NULL) return B_ERROR; if (msgRef() == NULL) return B_BAD_ARGUMENT;
MessageField * field = GetMessageField(fieldName, B_MESSAGE_TYPE); MessageField * field = GetMessageField(fieldName, B_MESSAGE_TYPE);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddMessage(fieldName, msgRef); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddMessage(fieldName, msgRef);
if (field) return field->ReplaceDataItem(index, &msgRef, sizeof(msgRef)); if (field) return field->ReplaceDataItem(index, &msgRef, sizeof(msgRef));
return B_ERROR; return B_DATA_NOT_FOUND;
} }
status_t Message :: ReplaceFlat(bool okayToAdd, const String & fieldName, uint32 index, const FlatCountableRef & ref) status_t Message :: ReplaceFlat(bool okayToAdd, const String & fieldName, uint32 index, const FlatCountableRef & ref)
{ {
const FlatCountable * fc = ref(); const FlatCountable * fc = ref();
if (fc) if (fc)
{ {
const uint32 tc = fc->TypeCode(); const uint32 tc = fc->TypeCode();
MessageField * field = GetMessageField(fieldName, tc); MessageField * field = GetMessageField(fieldName, tc);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) retur n AddFlat(fieldName, ref); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) retur n AddFlat(fieldName, ref);
if (field) if (field)
{ {
switch(tc) switch(tc)
{ {
case B_MESSAGE_TYPE: case B_MESSAGE_TYPE:
return (dynamic_cast<const Message *>(fc)) ? ReplaceMessage(okayT oAdd, fieldName, index, MessageRef(ref.GetRefCountableRef(), true)) : B_ERROR; return (dynamic_cast<const Message *>(fc)) ? ReplaceMessage(okayT oAdd, fieldName, index, MessageRef(ref.GetRefCountableRef(), true)) : B_TYPE_MIS MATCH;
default: default:
if (GetElementSize(tc) == 0) return field->ReplaceFlatCountableDa taItem(index, ref); if (GetElementSize(tc) == 0) return field->ReplaceFlatCountableDa taItem(index, ref);
break; break;
} }
} }
} }
return B_ERROR; return B_BAD_ARGUMENT;
} }
status_t Message :: ReplaceData(bool okayToAdd, const String & fieldName, uint32 type, uint32 index, const void * data, uint32 numBytes) status_t Message :: ReplaceData(bool okayToAdd, const String & fieldName, uint32 type, uint32 index, const void * data, uint32 numBytes)
{ {
TCHECKPOINT; TCHECKPOINT;
if (type == B_STRING_TYPE) if (type == B_STRING_TYPE)
{ {
String temp((const char *)data); // temp to avoid gcc optimizer bug String temp((const char *)data); // temp to avoid gcc optimizer bug
return ReplaceString(okayToAdd, fieldName, index, temp); return ReplaceString(okayToAdd, fieldName, index, temp);
} }
MessageField * field = GetMessageField(fieldName, type); MessageField * field = GetMessageField(fieldName, type);
if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddDataAux(fieldName, data, numBytes, type, false); if ((okayToAdd)&&((field == NULL)||(index >= field->GetNumItems()))) return A ddDataAux(fieldName, data, numBytes, type, false);
if (field == NULL) return B_ERROR; if (field == NULL) return B_DATA_NOT_FOUND;
// for primitive types, we do this: // for primitive types, we do this:
bool isVariableSize = false; bool isVariableSize = false;
uint32 elementSize = GetElementSize(type); uint32 elementSize = GetElementSize(type);
if (elementSize == 0) if (elementSize == 0)
{ {
// zero indicates a variable-sized data item // zero indicates a variable-sized data item
isVariableSize = true; isVariableSize = true;
elementSize = numBytes; elementSize = numBytes;
if (elementSize == 0) return B_ERROR; if (elementSize == 0) return B_TYPE_MISMATCH;
} }
if (numBytes % elementSize) return B_ERROR; // Can't add half an element, si lly! if (numBytes % elementSize) return B_BAD_ARGUMENT; // Can't add half an elem ent, silly!
const uint32 numElements = numBytes / elementSize; const uint32 numElements = numBytes / elementSize;
const uint8 * dataBuf = (const uint8 *) data; const uint8 * dataBuf = (const uint8 *) data;
for (uint32 i=index; i<index+numElements; i++) for (uint32 i=index; i<index+numElements; i++)
{ {
FlatCountableRef ref; FlatCountableRef ref;
const void * dataToAdd = &dataBuf[i*elementSize]; const void * dataToAdd = &dataBuf[i*elementSize];
uint32 addSize = elementSize; uint32 addSize = elementSize;
if (isVariableSize) if (isVariableSize)
{ {
ref.SetFromRefCountableRef(GetByteBufferFromPool(elementSize, (const ui nt8 *)dataToAdd).GetRefCountableRef()); ref.SetFromRefCountableRef(GetByteBufferFromPool(elementSize, (const ui nt8 *)dataToAdd).GetRefCountableRef());
if (ref() == NULL) {WARN_OUT_OF_MEMORY; return B_ERROR;} if (ref() == NULL) RETURN_OUT_OF_MEMORY;
dataToAdd = &ref; dataToAdd = &ref;
addSize = sizeof(ref); addSize = sizeof(ref);
} }
if (field->ReplaceDataItem(i, dataToAdd, addSize) != B_NO_ERROR) return B_
ERROR; status_t ret;
if (field->ReplaceDataItem(i, dataToAdd, addSize).IsError(ret)) return ret
;
} }
return B_NO_ERROR; return B_NO_ERROR;
} }
uint32 Message :: GetNumValuesInName(const String & fieldName, uint32 type) cons t uint32 Message :: GetNumValuesInName(const String & fieldName, uint32 type) cons t
{ {
const MessageField * field = GetMessageField(fieldName, type); const MessageField * field = GetMessageField(fieldName, type);
return field ? field->GetNumItems() : 0; return field ? field->GetNumItems() : 0;
} }
skipping to change at line 2069 skipping to change at line 2107
const MessageField * field = GetMessageField(fieldName, B_ANY_TYPE); const MessageField * field = GetMessageField(fieldName, B_ANY_TYPE);
return field ? field->TypeCode() : defaultTypeCode; return field ? field->TypeCode() : defaultTypeCode;
} }
status_t Message :: CopyName(const String & oldFieldName, Message & copyTo, cons t String & newFieldName) const status_t Message :: CopyName(const String & oldFieldName, Message & copyTo, cons t String & newFieldName) const
{ {
if ((this == &copyTo)&&(oldFieldName == newFieldName)) return B_NO_ERROR; // already done! if ((this == &copyTo)&&(oldFieldName == newFieldName)) return B_NO_ERROR; // already done!
const MessageField * mf = GetMessageField(oldFieldName, B_ANY_TYPE); const MessageField * mf = GetMessageField(oldFieldName, B_ANY_TYPE);
MessageField * newMF = mf ? copyTo._entries.PutAndGet(newFieldName, *mf) : NU LL; MessageField * newMF = mf ? copyTo._entries.PutAndGet(newFieldName, *mf) : NU LL;
return newMF ? newMF->EnsurePrivate() : B_ERROR; return newMF ? newMF->EnsurePrivate() : B_DATA_NOT_FOUND;
} }
status_t Message :: ShareName(const String & oldFieldName, Message & shareTo, co nst String & newFieldName) const status_t Message :: ShareName(const String & oldFieldName, Message & shareTo, co nst String & newFieldName) const
{ {
if ((this == &shareTo)&&(oldFieldName == newFieldName)) return B_NO_ERROR; / / already done! if ((this == &shareTo)&&(oldFieldName == newFieldName)) return B_NO_ERROR; / / already done!
const MessageField * mf = GetMessageField(oldFieldName, B_ANY_TYPE); const MessageField * mf = GetMessageField(oldFieldName, B_ANY_TYPE);
if (mf == NULL) return B_ERROR; if (mf == NULL) return B_DATA_NOT_FOUND;
// for non-array fields I'm falling back to copying rather than forcing a con st violation // for non-array fields I'm falling back to copying rather than forcing a con st violation
return mf->HasArray() ? shareTo._entries.Put(newFieldName, *mf) : CopyName(ol dFieldName, shareTo, newFieldName); return mf->HasArray() ? shareTo._entries.Put(newFieldName, *mf) : CopyName(ol dFieldName, shareTo, newFieldName);
} }
status_t Message :: MoveName(const String & oldFieldName, Message & moveTo, cons t String & newFieldName) status_t Message :: MoveName(const String & oldFieldName, Message & moveTo, cons t String & newFieldName)
{ {
if ((this == &moveTo)&&(oldFieldName == newFieldName)) return B_NO_ERROR; // already done! if ((this == &moveTo)&&(oldFieldName == newFieldName)) return B_NO_ERROR; // already done!
const MessageField * mf = GetMessageField(oldFieldName, B_ANY_TYPE); const MessageField * mf = GetMessageField(oldFieldName, B_ANY_TYPE);
if ((mf)&&(moveTo._entries.Put(newFieldName, *mf) == B_NO_ERROR)) if (mf == NULL) return B_DATA_NOT_FOUND;
status_t ret;
if (moveTo._entries.Put(newFieldName, *mf).IsOK(ret))
{ {
(void) _entries.Remove(oldFieldName); (void) _entries.Remove(oldFieldName);
return B_NO_ERROR; return B_NO_ERROR;
} }
else return B_ERROR; else return ret;
} }
status_t Message :: PrependString(const String & fieldName, const String & val) status_t Message :: PrependString(const String & fieldName, const String & val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_STRING_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_STRING_TYPE);
return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependInt8(const String & fieldName, int8 val) status_t Message :: PrependInt8(const String & fieldName, int8 val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_INT8_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_INT8_TYPE);
return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependInt16(const String & fieldName, int16 val) status_t Message :: PrependInt16(const String & fieldName, int16 val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_INT16_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_INT16_TYPE);
return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependInt32(const String & fieldName, int32 val) status_t Message :: PrependInt32(const String & fieldName, int32 val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_INT32_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_INT32_TYPE);
return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependInt64(const String & fieldName, int64 val) status_t Message :: PrependInt64(const String & fieldName, int64 val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_INT64_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_INT64_TYPE);
return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependBool(const String & fieldName, bool val) status_t Message :: PrependBool(const String & fieldName, bool val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_BOOL_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_BOOL_TYPE);
return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependFloat(const String & fieldName, float val) status_t Message :: PrependFloat(const String & fieldName, float val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_FLOAT_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_FLOAT_TYPE);
return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependDouble(const String & fieldName, double val) status_t Message :: PrependDouble(const String & fieldName, double val)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_DOUBLE_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_DOUBLE_TYPE);
return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_ERROR; return mf ? mf->PrependDataItem(&val, sizeof(val)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependPointer(const String & fieldName, const void * ptr) status_t Message :: PrependPointer(const String & fieldName, const void * ptr)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_POINTER_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_POINTER_TYPE);
return mf ? mf->PrependDataItem(&ptr, sizeof(ptr)) : B_ERROR; return mf ? mf->PrependDataItem(&ptr, sizeof(ptr)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependPoint(const String & fieldName, const Point & point) status_t Message :: PrependPoint(const String & fieldName, const Point & point)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_POINT_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_POINT_TYPE);
return mf ? mf->PrependDataItem(&point, sizeof(point)) : B_ERROR; return mf ? mf->PrependDataItem(&point, sizeof(point)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependRect(const String & fieldName, const Rect & rect) status_t Message :: PrependRect(const String & fieldName, const Rect & rect)
{ {
MessageField * mf = GetOrCreateMessageField(fieldName, B_RECT_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_RECT_TYPE);
return mf ? mf->PrependDataItem(&rect, sizeof(rect)) : B_ERROR; return mf ? mf->PrependDataItem(&rect, sizeof(rect)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependTag(const String & fieldName, const RefCountableRef & tag) status_t Message :: PrependTag(const String & fieldName, const RefCountableRef & tag)
{ {
if (tag() == NULL) return B_ERROR; if (tag() == NULL) return B_BAD_ARGUMENT;
MessageField * mf = GetOrCreateMessageField(fieldName, B_TAG_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_TAG_TYPE);
return mf ? mf->PrependDataItem(&tag, sizeof(tag)) : B_ERROR; return mf ? mf->PrependDataItem(&tag, sizeof(tag)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependMessage(const String & fieldName, const MessageRef & ref) status_t Message :: PrependMessage(const String & fieldName, const MessageRef & ref)
{ {
if (ref() == NULL) return B_ERROR; if (ref() == NULL) return B_BAD_ARGUMENT;
MessageField * mf = GetOrCreateMessageField(fieldName, B_MESSAGE_TYPE); MessageField * mf = GetOrCreateMessageField(fieldName, B_MESSAGE_TYPE);
return mf ? mf->PrependDataItem(&ref, sizeof(ref)) : B_ERROR; return mf ? mf->PrependDataItem(&ref, sizeof(ref)) : B_TYPE_MISMATCH;
} }
status_t Message :: PrependFlat(const String & fieldName, const FlatCountableRef & ref) status_t Message :: PrependFlat(const String & fieldName, const FlatCountableRef & ref)
{ {
FlatCountable * fc = ref(); FlatCountable * fc = ref();
if (fc) if (fc)
{ {
const uint32 tc = fc->TypeCode(); const uint32 tc = fc->TypeCode();
switch(tc) switch(tc)
{ {
case B_STRING_TYPE: return B_ERROR; // sorry, can't do that (Strings case B_STRING_TYPE: return B_TYPE_MISMATCH; // sorry, can't do that (
aren't FlatCountables) Strings aren't FlatCountables)
case B_POINT_TYPE: return B_ERROR; // sorry, can't do that (Strings case B_POINT_TYPE: return B_TYPE_MISMATCH; // sorry, can't do that (
aren't FlatCountables) Strings aren't FlatCountables)
case B_RECT_TYPE: return B_ERROR; // sorry, can't do that (Strings case B_RECT_TYPE: return B_TYPE_MISMATCH; // sorry, can't do that (
aren't FlatCountables) Strings aren't FlatCountables)
case B_MESSAGE_TYPE: return PrependMessage(fieldName, MessageRef(ref.Ge tRefCountableRef(), true)); case B_MESSAGE_TYPE: return PrependMessage(fieldName, MessageRef(ref.Ge tRefCountableRef(), true));
default: return AddFlatAux(fieldName, ref, tc, true); default: return AddFlatAux(fieldName, ref, tc, true);
} }
} }
return B_ERROR; return B_BAD_ARGUMENT;
} }
status_t Message :: CopyFromImplementation(const Flattenable & copyFrom) status_t Message :: CopyFromImplementation(const Flattenable & copyFrom)
{ {
const Message * cMsg = dynamic_cast<const Message *>(&copyFrom); const Message * cMsg = dynamic_cast<const Message *>(&copyFrom);
if (cMsg) if (cMsg)
{ {
*this = *cMsg; *this = *cMsg;
return B_NO_ERROR; return B_NO_ERROR;
} }
skipping to change at line 2341 skipping to change at line 2382
if (fc) fc->Flatten(buffer); if (fc) fc->Flatten(buffer);
} }
break; break;
} }
} }
// Note: we assume here that we have enough bytes, at least for the fixed-size types, because we checked for that in MessageField::Unflatten() // Note: we assume here that we have enough bytes, at least for the fixed-size types, because we checked for that in MessageField::Unflatten()
status_t MessageField :: SingleUnflatten(const uint8 * buffer, uint32 numBytes) status_t MessageField :: SingleUnflatten(const uint8 * buffer, uint32 numBytes)
{ {
status_t ret;
switch(_typeCode) switch(_typeCode)
{ {
case B_BOOL_TYPE: SetInlineItemAsBool( buffer[0] != 0); break; case B_BOOL_TYPE: SetInlineItemAsBool( buffer[0] != 0); break;
case B_DOUBLE_TYPE: SetInlineItemAsDouble(B_LENDIAN_TO_HOST_IDOUBLE(muscle CopyIn<uint64>(buffer))); break; case B_DOUBLE_TYPE: SetInlineItemAsDouble(B_LENDIAN_TO_HOST_IDOUBLE(muscle CopyIn<uint64>(buffer))); break;
case B_FLOAT_TYPE: SetInlineItemAsFloat( B_LENDIAN_TO_HOST_IFLOAT(muscleC opyIn<uint32>(buffer))); break; case B_FLOAT_TYPE: SetInlineItemAsFloat( B_LENDIAN_TO_HOST_IFLOAT(muscleC opyIn<uint32>(buffer))); break;
case B_INT64_TYPE: SetInlineItemAsInt64( B_LENDIAN_TO_HOST_INT64(muscleCo pyIn<uint64>(buffer))); break; case B_INT64_TYPE: SetInlineItemAsInt64( B_LENDIAN_TO_HOST_INT64(muscleCo pyIn<uint64>(buffer))); break;
case B_INT32_TYPE: SetInlineItemAsInt32( B_LENDIAN_TO_HOST_INT32(muscleCo pyIn<uint32>(buffer))); break; case B_INT32_TYPE: SetInlineItemAsInt32( B_LENDIAN_TO_HOST_INT32(muscleCo pyIn<uint32>(buffer))); break;
case B_INT16_TYPE: SetInlineItemAsInt16( B_LENDIAN_TO_HOST_INT16(muscleCo pyIn<uint16>(buffer))); break; case B_INT16_TYPE: SetInlineItemAsInt16( B_LENDIAN_TO_HOST_INT16(muscleCo pyIn<uint16>(buffer))); break;
case B_INT8_TYPE: SetInlineItemAsInt8( *buffer); break; case B_INT8_TYPE: SetInlineItemAsInt8( *buffer); break;
case B_MESSAGE_TYPE: case B_MESSAGE_TYPE:
{ {
if (numBytes < sizeof(uint32)) return B_ERROR; // huh? if (numBytes < sizeof(uint32)) return B_BAD_DATA; // huh?
// Note: Message fields have no number-of-items field, for historical reasons // Note: Message fields have no number-of-items field, for historical reasons
const uint32 msgSize = B_LENDIAN_TO_HOST_INT32(muscleCopyIn<uint32>(buf fer)); const uint32 msgSize = B_LENDIAN_TO_HOST_INT32(muscleCopyIn<uint32>(buf fer));
buffer += sizeof(uint32); numBytes -= sizeof(uint32); // this line mus t be exactly here! buffer += sizeof(uint32); numBytes -= sizeof(uint32); // this line mus t be exactly here!
if (msgSize != numBytes) return B_ERROR; if (msgSize != numBytes) return B_BAD_DATA;
MessageRef msgRef = GetMessageFromPool(buffer, numBytes); MessageRef msgRef = GetMessageFromPool(buffer, numBytes);
if (msgRef() == NULL) return B_ERROR; if (msgRef() == NULL) return B_OUT_OF_MEMORY;
SetInlineItemAsRefCountableRef(msgRef.GetRefCountableRef()); SetInlineItemAsRefCountableRef(msgRef.GetRefCountableRef());
} }
break; break;
case B_POINTER_TYPE: return B_ERROR; // pointers should not be serialized case B_POINTER_TYPE: return B_UNIMPLEMENTED; // pointers should not be se
! rialized!
case B_POINT_TYPE: {Point p; if (p.Unflatten(buffer, numBytes) == B_NO_E case B_POINT_TYPE: {Point p; if (p.Unflatten(buffer, numBytes).IsOK(ret)
RROR) SetInlineItemAsPoint(p); else return B_ERROR;} break; ) SetInlineItemAsPoint(p); else return ret;} break;
case B_RECT_TYPE: {Rect r; if (r.Unflatten(buffer, numBytes) == B_NO_E case B_RECT_TYPE: {Rect r; if (r.Unflatten(buffer, numBytes).IsOK(ret)
RROR) SetInlineItemAsRect (r); else return B_ERROR;} break; ) SetInlineItemAsRect (r); else return ret;} break;
case B_STRING_TYPE: case B_STRING_TYPE:
{ {
if (numBytes < sizeof(uint32)) return B_ERROR; // paranoia if (numBytes < sizeof(uint32)) return B_BAD_DATA; // paranoia
// string type follows the variable-sized-objects-field convention // string type follows the variable-sized-objects-field convention
const uint32 itemCount = B_LENDIAN_TO_HOST_INT32(muscleCopyIn<uint32>(b uffer)); const uint32 itemCount = B_LENDIAN_TO_HOST_INT32(muscleCopyIn<uint32>(b uffer));
if (itemCount != 1) return B_ERROR; // wtf, if we're in this function there should only be one item! if (itemCount != 1) return B_LOGIC_ERROR; // wtf, if we're in this fun ction there should only be one item!
buffer += sizeof(uint32); numBytes -= sizeof(uint32); buffer += sizeof(uint32); numBytes -= sizeof(uint32);
const uint32 itemSize = B_LENDIAN_TO_HOST_INT32(muscleCopyIn<uint32>(bu ffer)); const uint32 itemSize = B_LENDIAN_TO_HOST_INT32(muscleCopyIn<uint32>(bu ffer));
buffer += sizeof(uint32); numBytes -= sizeof(uint32); // yes, this lin e MUST be exactly here! buffer += sizeof(uint32); numBytes -= sizeof(uint32); // yes, this lin e MUST be exactly here!
if (itemSize != numBytes) return B_ERROR; // our one item should take up the entire buffer, or something is wrong if (itemSize != numBytes) return B_LOGIC_ERROR; // our one item should take up the entire buffer, or something is wrong
String s; String s;
if (s.Unflatten(buffer, numBytes) != B_NO_ERROR) return B_ERROR; if (s.Unflatten(buffer, numBytes).IsError(ret)) return ret;
SetInlineItemAsString(s); SetInlineItemAsString(s);
} }
break; break;
case B_TAG_TYPE: return B_ERROR; // tags should not be serialized! case B_TAG_TYPE: return B_UNIMPLEMENTED; // tags should not be serial ized!
default: default:
{ {
if (numBytes < sizeof(uint32)) return B_ERROR; // paranoia if (numBytes < sizeof(uint32)) return B_BAD_DATA; // paranoia
// all other types will follow the variable-sized-objects-field convent ion // all other types will follow the variable-sized-objects-field convent ion
const uint32 itemCount = B_LENDIAN_TO_HOST_INT32(muscleCopyIn<uint32>(b uffer)); const uint32 itemCount = B_LENDIAN_TO_HOST_INT32(muscleCopyIn<uint32>(b uffer));
if (itemCount != 1) return B_ERROR; // wtf, if we're in this function there should only be one item! if (itemCount != 1) return B_LOGIC_ERROR; // wtf, if we're in this fun ction there should only be one item!
buffer += sizeof(uint32); numBytes -= sizeof(uint32); buffer += sizeof(uint32); numBytes -= sizeof(uint32);
const uint32 itemSize = B_LENDIAN_TO_HOST_INT32(muscleCopyIn<uint32>(bu ffer)); const uint32 itemSize = B_LENDIAN_TO_HOST_INT32(muscleCopyIn<uint32>(bu ffer));
buffer += sizeof(uint32); numBytes -= sizeof(uint32); // yes, this lin e MUST be exactly here! buffer += sizeof(uint32); numBytes -= sizeof(uint32); // yes, this lin e MUST be exactly here!
if (itemSize != numBytes) return B_ERROR; // our one item should take up the entire buffer, or something is wrong if (itemSize != numBytes) return B_LOGIC_ERROR; // our one item should take up the entire buffer, or something is wrong
ByteBufferRef bbRef = GetByteBufferFromPool(numBytes, buffer); ByteBufferRef bbRef = GetByteBufferFromPool(numBytes, buffer);
if (bbRef() == NULL) return B_ERROR; if (bbRef() == NULL) return B_OUT_OF_MEMORY;
SetInlineItemAsRefCountableRef(bbRef.GetRefCountableRef()); SetInlineItemAsRefCountableRef(bbRef.GetRefCountableRef());
} }
break; break;
} }
_state = FIELD_STATE_INLINE; _state = FIELD_STATE_INLINE;
return B_NO_ERROR; return B_NO_ERROR;
} }
skipping to change at line 2460 skipping to change at line 2502
AbstractDataArrayRef adaRef = CreateDataArray(_typeCode); AbstractDataArrayRef adaRef = CreateDataArray(_typeCode);
if ((adaRef())&&(adaRef()->AddDataItem(_union._data, size) == B_NO_ERROR)) // add our existing single-item to the array if ((adaRef())&&(adaRef()->AddDataItem(_union._data, size) == B_NO_ERROR)) // add our existing single-item to the array
{ {
if (adaRef()->AddDataItem(data, size) == B_NO_ERROR) if (adaRef()->AddDataItem(data, size) == B_NO_ERROR)
{ {
_state = FIELD_STATE_ARRAY; _state = FIELD_STATE_ARRAY;
SetInlineItemAsRefCountableRef(adaRef.GetRefCountableRef()); SetInlineItemAsRefCountableRef(adaRef.GetRefCountableRef());
return B_NO_ERROR; return B_NO_ERROR;
} }
} }
return B_ERROR; return B_OUT_OF_MEMORY;
} }
} }
status_t MessageField :: SingleRemoveDataItem(uint32 index) status_t MessageField :: SingleRemoveDataItem(uint32 index)
{ {
if ((index > 0)||(_state != FIELD_STATE_INLINE)) return B_ERROR; if ((index > 0)||(_state != FIELD_STATE_INLINE)) return B_BAD_ARGUMENT;
SetInlineItemToNull(); SetInlineItemToNull();
_state = FIELD_STATE_EMPTY; _state = FIELD_STATE_EMPTY;
return B_NO_ERROR; return B_NO_ERROR;
} }
status_t MessageField :: SinglePrependDataItem(const void * data, uint32 size) status_t MessageField :: SinglePrependDataItem(const void * data, uint32 size)
{ {
if (_state == FIELD_STATE_EMPTY) if (_state == FIELD_STATE_EMPTY)
{ {
skipping to change at line 2494 skipping to change at line 2536
AbstractDataArrayRef adaRef = CreateDataArray(_typeCode); AbstractDataArrayRef adaRef = CreateDataArray(_typeCode);
if ((adaRef())&&(adaRef()->AddDataItem(_union._data, size) == B_NO_ERROR)) // add our existing single-item to the array if ((adaRef())&&(adaRef()->AddDataItem(_union._data, size) == B_NO_ERROR)) // add our existing single-item to the array
{ {
if (adaRef()->PrependDataItem(data, size) == B_NO_ERROR) if (adaRef()->PrependDataItem(data, size) == B_NO_ERROR)
{ {
_state = FIELD_STATE_ARRAY; _state = FIELD_STATE_ARRAY;
SetInlineItemAsRefCountableRef(adaRef.GetRefCountableRef()); SetInlineItemAsRefCountableRef(adaRef.GetRefCountableRef());
return B_NO_ERROR; return B_NO_ERROR;
} }
} }
return B_ERROR; return B_OUT_OF_MEMORY;
} }
} }
status_t MessageField :: SingleFindDataItem(uint32 index, const void ** setDataL oc) const status_t MessageField :: SingleFindDataItem(uint32 index, const void ** setDataL oc) const
{ {
if ((_state != FIELD_STATE_INLINE)||(index > 0)) return B_ERROR; if ((_state != FIELD_STATE_INLINE)||(index > 0)) return B_BAD_ARGUMENT;
*setDataLoc = _union._data; *setDataLoc = _union._data;
return B_NO_ERROR; return B_NO_ERROR;
} }
status_t MessageField :: SingleReplaceDataItem(uint32 index, const void * data, uint32 size) status_t MessageField :: SingleReplaceDataItem(uint32 index, const void * data, uint32 size)
{ {
if ((_state != FIELD_STATE_INLINE)||(index > 0)) return B_ERROR; if ((_state != FIELD_STATE_INLINE)||(index > 0)) return B_BAD_ARGUMENT;
SingleSetValue(data, size); SingleSetValue(data, size);
return B_NO_ERROR; return B_NO_ERROR;
} }
// For a given absolutely-fixed-size-type, returns the number of bytes that this type will flatten to. // For a given absolutely-fixed-size-type, returns the number of bytes that this type will flatten to.
// For any other types, returns 0. // For any other types, returns 0.
static uint32 GetFlattenedSizeForFixedSizeType(uint32 typeCode) static uint32 GetFlattenedSizeForFixedSizeType(uint32 typeCode)
{ {
switch(typeCode) switch(typeCode)
skipping to change at line 2827 skipping to change at line 2869
} }
status_t MessageField :: EnsurePrivate() status_t MessageField :: EnsurePrivate()
{ {
switch(_state) switch(_state)
{ {
case FIELD_STATE_ARRAY: case FIELD_STATE_ARRAY:
if (GetArrayRef().IsRefPrivate() == false) if (GetArrayRef().IsRefPrivate() == false)
{ {
AbstractDataArrayRef newArrayCopy = GetArray()->Clone(); AbstractDataArrayRef newArrayCopy = GetArray()->Clone();
if (newArrayCopy() == NULL) return B_ERROR; if (newArrayCopy() == NULL) return B_OUT_OF_MEMORY;
SetInlineItemAsRefCountableRef(newArrayCopy.GetRefCountableRef()); SetInlineItemAsRefCountableRef(newArrayCopy.GetRefCountableRef());
} }
break; break;
case FIELD_STATE_INLINE: case FIELD_STATE_INLINE:
if (_dataType == DATA_TYPE_REF) if (_dataType == DATA_TYPE_REF)
{ {
const RefCountableRef & rcRef = GetInlineItemAsRefCountableRef(); const RefCountableRef & rcRef = GetInlineItemAsRefCountableRef();
if ((rcRef())&&(GetArrayRef().IsRefPrivate() == false)) if ((rcRef())&&(GetArrayRef().IsRefPrivate() == false))
{ {
const Message * msg = dynamic_cast<const Message *>(rcRef()); const Message * msg = dynamic_cast<const Message *>(rcRef());
if (msg) if (msg)
{ {
MessageRef newMsg = GetMessageFromPool(*msg); MessageRef newMsg = GetMessageFromPool(*msg);
if (newMsg() == NULL) return B_ERROR; if (newMsg() == NULL) return B_OUT_OF_MEMORY;
SetInlineItemAsRefCountableRef(newMsg.GetRefCountableRef()); SetInlineItemAsRefCountableRef(newMsg.GetRefCountableRef());
} }
else else
{ {
const FlatCountable * fc = dynamic_cast<const FlatCountable *> (rcRef()); const FlatCountable * fc = dynamic_cast<const FlatCountable *> (rcRef());
if (fc) if (fc)
{ {
ByteBufferRef newBuf = fc->FlattenToByteBuffer(); ByteBufferRef newBuf = fc->FlattenToByteBuffer();
if (newBuf() == NULL) return B_ERROR; if (newBuf() == NULL) return B_BAD_OBJECT;
SetInlineItemAsRefCountableRef(newBuf.GetRefCountableRef()) ; SetInlineItemAsRefCountableRef(newBuf.GetRefCountableRef()) ;
} }
} }
} }
} }
break; break;
default: default:
// do nothing // do nothing
break; break;
skipping to change at line 2873 skipping to change at line 2915
return B_NO_ERROR; return B_NO_ERROR;
} }
status_t MessageField :: ReplaceFlatCountableDataItem(uint32 index, muscle::Ref< muscle::FlatCountable> const & fcRef) status_t MessageField :: ReplaceFlatCountableDataItem(uint32 index, muscle::Ref< muscle::FlatCountable> const & fcRef)
{ {
switch(_state) switch(_state)
{ {
case FIELD_STATE_INLINE: case FIELD_STATE_INLINE:
SetInlineItemAsRefCountableRef(fcRef.GetRefCountableRef()); SetInlineItemAsRefCountableRef(fcRef.GetRefCountableRef());
break; return B_NO_ERROR;
case FIELD_STATE_ARRAY: case FIELD_STATE_ARRAY:
{ {
// Note that I don't check for MessageDataArray here since it's already been handled in the calling method // Note that I don't check for MessageDataArray here since it's already been handled in the calling method
ByteBufferDataArray * bbda = dynamic_cast<ByteBufferDataArray *>(GetArr ay()); ByteBufferDataArray * bbda = dynamic_cast<ByteBufferDataArray *>(GetArr ay());
if (bbda) if (bbda)
{ {
ByteBufferRef bbRef(fcRef.GetRefCountableRef(), true); ByteBufferRef bbRef(fcRef.GetRefCountableRef(), true);
return bbRef() ? bbda->ReplaceDataItem(index, &bbRef, sizeof(bbRef)) : B_ERROR; return bbRef() ? bbda->ReplaceDataItem(index, &bbRef, sizeof(bbRef)) : B_TYPE_MISMATCH;
} }
TagDataArray * tda = dynamic_cast<TagDataArray *>(GetArray()); TagDataArray * tda = dynamic_cast<TagDataArray *>(GetArray());
if (tda) if (tda)
{ {
RefCountableRef rcRef = fcRef.GetRefCountableRef(); RefCountableRef rcRef = fcRef.GetRefCountableRef();
return tda->ReplaceDataItem(index, &rcRef, sizeof(rcRef)); return tda->ReplaceDataItem(index, &rcRef, sizeof(rcRef));
} }
return B_BAD_OBJECT;
} }
break; break;
case FIELD_STATE_EMPTY: return B_DATA_NOT_FOUND;
default: return B_LOGIC_ERROR;
} }
return B_ERROR;
} }
uint32 MessageField :: GetNumItemsInFlattenedBuffer(const uint8 * bytes, uint32 numBytes) const uint32 MessageField :: GetNumItemsInFlattenedBuffer(const uint8 * bytes, uint32 numBytes) const
{ {
const uint32 fsItemSize = GetFlattenedSizeForFixedSizeType(_typeCode); const uint32 fsItemSize = GetFlattenedSizeForFixedSizeType(_typeCode);
if (fsItemSize > 0) return numBytes/fsItemSize; if (fsItemSize > 0) return numBytes/fsItemSize;
else if (_typeCode == B_MESSAGE_TYPE) else if (_typeCode == B_MESSAGE_TYPE)
{ {
// special case for the Message type since it doesn't have a number-of-ite ms-count, annoyingly enough // special case for the Message type since it doesn't have a number-of-ite ms-count, annoyingly enough
skipping to change at line 2930 skipping to change at line 2976
status_t MessageField :: Unflatten(const uint8 * bytes, uint32 numBytes) status_t MessageField :: Unflatten(const uint8 * bytes, uint32 numBytes)
{ {
_state = FIELD_STATE_EMPTY; // semi-paranoia _state = FIELD_STATE_EMPTY; // semi-paranoia
SetInlineItemToNull(); // ditto SetInlineItemToNull(); // ditto
const uint32 numItemsInBuffer = GetNumItemsInFlattenedBuffer(bytes, numBytes) ; const uint32 numItemsInBuffer = GetNumItemsInFlattenedBuffer(bytes, numBytes) ;
if (numItemsInBuffer == 1) return SingleUnflatten(bytes, numBytes); if (numItemsInBuffer == 1) return SingleUnflatten(bytes, numBytes);
else else
{ {
AbstractDataArrayRef adaRef = CreateDataArray(_typeCode); AbstractDataArrayRef adaRef = CreateDataArray(_typeCode);
if ((adaRef())&&(adaRef()->Unflatten(bytes, numBytes) == B_NO_ERROR)) // if (adaRef() == NULL) return B_OUT_OF_MEMORY;
add our existing single-item to the array
status_t ret;
if (adaRef()->Unflatten(bytes, numBytes).IsOK(ret)) // add our existing s
ingle-item to the array
{ {
_state = FIELD_STATE_ARRAY; _state = FIELD_STATE_ARRAY;
SetInlineItemAsRefCountableRef(adaRef.GetRefCountableRef()); SetInlineItemAsRefCountableRef(adaRef.GetRefCountableRef());
return B_NO_ERROR; return B_NO_ERROR;
} }
else return ret;
} }
return B_ERROR;
} }
const Rect & MessageField :: GetItemAtAsRect(uint32 index) const const Rect & MessageField :: GetItemAtAsRect(uint32 index) const
{ {
switch(_state) switch(_state)
{ {
case FIELD_STATE_ARRAY: case FIELD_STATE_ARRAY:
{ {
const RectDataArray * rda = dynamic_cast<const RectDataArray *>(GetArra y()); const RectDataArray * rda = dynamic_cast<const RectDataArray *>(GetArra y());
if (rda) return rda->ItemAt(index); if (rda) return rda->ItemAt(index);
 End of changes. 190 change blocks. 
266 lines changed or deleted 323 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)