mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-15 17:40:35 -04:00
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:
parent
3f4c1a1baf
commit
17d87617c8
1 changed files with 55 additions and 55 deletions
|
@ -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
|
template<class ID_CLASS,uint32_t TLV_TYPE> class t_RsTlvIdSet: public RsTlvItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
t_RsTlvIdSet() {}
|
t_RsTlvIdSet() {}
|
||||||
virtual ~t_RsTlvIdSet() {}
|
virtual ~t_RsTlvIdSet() {}
|
||||||
|
|
||||||
virtual uint32_t TlvSize() { return ID_CLASS::SIZE_IN_BYTES * ids.size() + TLV_HEADER_SIZE; }
|
virtual uint32_t TlvSize() { return ID_CLASS::SIZE_IN_BYTES * ids.size() + TLV_HEADER_SIZE; }
|
||||||
virtual void TlvClear(){ ids.clear() ; }
|
virtual void TlvClear(){ ids.clear() ; }
|
||||||
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) /* serialise */
|
||||||
{ /* must check sizes */
|
{ /* must check sizes */
|
||||||
uint32_t tlvsize = TlvSize();
|
uint32_t tlvsize = TlvSize();
|
||||||
uint32_t tlvend = *offset + tlvsize;
|
uint32_t tlvend = *offset + tlvsize;
|
||||||
|
|
||||||
if (size < tlvend)
|
if (size < tlvend)
|
||||||
return false; /* not enough space */
|
return false; /* not enough space */
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
/* start at data[offset] */
|
/* start at data[offset] */
|
||||||
ok = ok && SetTlvBase(data, tlvend, offset, TLV_TYPE, tlvsize);
|
ok = ok && SetTlvBase(data, tlvend, offset, TLV_TYPE, tlvsize);
|
||||||
|
|
||||||
for(typename std::list<ID_CLASS>::const_iterator it(ids.begin());it!=ids.end();++it)
|
for(typename std::list<ID_CLASS>::const_iterator it(ids.begin());it!=ids.end();++it)
|
||||||
ok = ok && (*it).serialise(data,size,*offset) ;
|
ok = ok && (*it).serialise(data,size,*offset) ;
|
||||||
|
|
||||||
return ok ;
|
return ok ;
|
||||||
}
|
}
|
||||||
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset) /* deserialise */
|
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset) /* deserialise */
|
||||||
{
|
{
|
||||||
if (size < *offset + TLV_HEADER_SIZE)
|
if (size < *offset + TLV_HEADER_SIZE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
uint16_t tlvtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
|
||||||
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
uint32_t tlvsize = GetTlvSize( &(((uint8_t *) data)[*offset]) );
|
||||||
uint32_t tlvend = *offset + tlvsize;
|
uint32_t tlvend = *offset + tlvsize;
|
||||||
|
|
||||||
if (size < tlvend) /* check size */
|
if (size < tlvend) /* check size */
|
||||||
return false; /* not enough space */
|
return false; /* not enough space */
|
||||||
|
|
||||||
if (tlvtype != TLV_TYPE) /* check type */
|
if (tlvtype != TLV_TYPE) /* check type */
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
/* ready to load */
|
/* ready to load */
|
||||||
TlvClear();
|
TlvClear();
|
||||||
|
|
||||||
/* skip the header */
|
/* skip the header */
|
||||||
(*offset) += TLV_HEADER_SIZE;
|
(*offset) += TLV_HEADER_SIZE;
|
||||||
|
|
||||||
while(*offset + ID_CLASS::SIZE_IN_BYTES < tlvend)
|
while(*offset + ID_CLASS::SIZE_IN_BYTES <= tlvend)
|
||||||
{
|
{
|
||||||
ID_CLASS id ;
|
ID_CLASS id ;
|
||||||
ok = ok && id.deserialise(data,size,*offset) ;
|
ok = ok && id.deserialise(data,size,*offset) ;
|
||||||
ids.push_back(id) ;
|
ids.push_back(id) ;
|
||||||
}
|
}
|
||||||
if(*offset != tlvsize)
|
if(*offset != tlvend)
|
||||||
std::cerr << "(EE) deserialisaiton error in " << __PRETTY_FUNCTION__ << std::endl;
|
std::cerr << "(EE) deserialisaiton error in " << __PRETTY_FUNCTION__ << std::endl;
|
||||||
return *offset == tlvsize ;
|
return *offset == tlvend ;
|
||||||
}
|
}
|
||||||
virtual std::ostream &print(std::ostream &out, uint16_t indent)
|
virtual std::ostream &print(std::ostream &out, uint16_t indent)
|
||||||
{
|
{
|
||||||
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
|
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
|
||||||
return out ;
|
return out ;
|
||||||
}
|
}
|
||||||
virtual std::ostream &printHex(std::ostream &out, uint16_t indent) /* SPECIAL One */
|
virtual std::ostream &printHex(std::ostream &out, uint16_t indent) /* SPECIAL One */
|
||||||
{
|
{
|
||||||
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
|
std::cerr << __PRETTY_FUNCTION__ << ": not implemented" << std::endl;
|
||||||
return out ;
|
return out ;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<ID_CLASS> ids ;
|
std::list<ID_CLASS> ids ;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef t_RsTlvIdSet<RsPeerId,TLV_TYPE_PEERSET> RsTlvPeerIdSet ;
|
typedef t_RsTlvIdSet<RsPeerId,TLV_TYPE_PEERSET> RsTlvPeerIdSet ;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue