bugfix in serialisation of tlvIdsSet

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.6-IdCleaning@7144 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2014-02-22 20:39:25 +00:00
parent 3f4c1a1baf
commit 17d87617c8

View file

@ -118,75 +118,75 @@ virtual std::ostream &printHex(std::ostream &out, uint16_t indent); /* SPECIAL O
template<class ID_CLASS,uint32_t TLV_TYPE> class t_RsTlvIdSet: public RsTlvItem
{
public:
t_RsTlvIdSet() {}
virtual ~t_RsTlvIdSet() {}
public:
t_RsTlvIdSet() {}
virtual ~t_RsTlvIdSet() {}
virtual uint32_t TlvSize() { return ID_CLASS::SIZE_IN_BYTES * ids.size() + TLV_HEADER_SIZE; }
virtual void TlvClear(){ ids.clear() ; }
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
{ /* must check sizes */
uint32_t tlvsize = TlvSize();
uint32_t tlvend = *offset + tlvsize;
virtual uint32_t TlvSize() { return ID_CLASS::SIZE_IN_BYTES * ids.size() + TLV_HEADER_SIZE; }
virtual void TlvClear(){ ids.clear() ; }
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
{ /* must check sizes */
uint32_t tlvsize = TlvSize();
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend)
return false; /* not enough space */
if (size < tlvend)
return false; /* not enough space */
bool ok = true;
bool ok = true;
/* start at data[offset] */
ok = ok && SetTlvBase(data, tlvend, offset, TLV_TYPE, tlvsize);
/* start at data[offset] */
ok = ok && SetTlvBase(data, tlvend, offset, TLV_TYPE, tlvsize);
for(typename std::list<ID_CLASS>::const_iterator it(ids.begin());it!=ids.end();++it)
ok = ok && (*it).serialise(data,size,*offset) ;
for(typename std::list<ID_CLASS>::const_iterator it(ids.begin());it!=ids.end();++it)
ok = ok && (*it).serialise(data,size,*offset) ;
return ok ;
}
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset) /* deserialise */
{
if (size < *offset + TLV_HEADER_SIZE)
return false;
return ok ;
}
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset) /* deserialise */
{
if (size < *offset + TLV_HEADER_SIZE)
return false;
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
uint32_t tlvend = *offset + tlvsize;
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
uint32_t tlvend = *offset + tlvsize;
if (size < tlvend) /* check size */
return false; /* not enough space */
if (size < tlvend) /* check size */
return false; /* not enough space */
if (tlvtype != TLV_TYPE) /* check type */
return false;
if (tlvtype != TLV_TYPE) /* check type */
return false;
bool ok = true;
bool ok = true;
/* ready to load */
TlvClear();
/* ready to load */
TlvClear();
/* skip the header */
(*offset) += TLV_HEADER_SIZE;
/* skip the header */
(*offset) += TLV_HEADER_SIZE;
while(*offset + ID_CLASS::SIZE_IN_BYTES < tlvend)
{
ID_CLASS id ;
ok = ok && id.deserialise(data,size,*offset) ;
ids.push_back(id) ;
}
if(*offset != tlvsize)
std::cerr << "(EE) deserialisaiton error in " << __PRETTY_FUNCTION__ << std::endl;
return *offset == tlvsize ;
}
virtual std::ostream &print(std::ostream &out, uint16_t indent)
{
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
return out ;
}
virtual std::ostream &printHex(std::ostream &out, uint16_t indent) /* SPECIAL One */
{
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
return out ;
}
while(*offset + ID_CLASS::SIZE_IN_BYTES <= tlvend)
{
ID_CLASS id ;
ok = ok && id.deserialise(data,size,*offset) ;
ids.push_back(id) ;
}
if(*offset != tlvend)
std::cerr << "(EE) deserialisaiton error in " << __PRETTY_FUNCTION__ << std::endl;
return *offset == tlvend ;
}
virtual std::ostream &print(std::ostream &out, uint16_t indent)
{
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
return out ;
}
virtual std::ostream &printHex(std::ostream &out, uint16_t indent) /* SPECIAL One */
{
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
return out ;
}
std::list<ID_CLASS> ids ;
std::list<ID_CLASS> ids ;
};
typedef t_RsTlvIdSet<RsPeerId,TLV_TYPE_PEERSET> RsTlvPeerIdSet ;