fixed saving of MsgItems for distant messages. Reworked RsMsgItem class hierarchy to remove explicit overloading by callign dynamic_cast

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6556 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-08-04 20:09:26 +00:00
parent 7dbc17b2a4
commit e763f46aee
2 changed files with 189 additions and 326 deletions

View File

@ -511,9 +511,7 @@ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
@ -555,9 +553,7 @@ bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
@ -605,9 +601,7 @@ bool RsChatLobbyListItem_deprecated::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
return ok ; return ok ;
} }
@ -640,9 +634,7 @@ bool RsChatLobbyListItem_deprecated2::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
return ok ; return ok ;
} }
@ -676,9 +668,7 @@ bool RsChatLobbyListItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
return ok ; return ok ;
} }
@ -704,9 +694,7 @@ bool RsChatLobbyEventItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
@ -730,9 +718,7 @@ bool RsChatLobbyUnsubscribeItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
@ -756,9 +742,7 @@ bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
@ -785,9 +769,7 @@ bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
@ -830,9 +812,7 @@ bool RsPrivateChatMsgConfigItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
return ok; return ok;
@ -873,9 +853,7 @@ bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsi
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
return ok; return ok;
@ -910,9 +888,7 @@ bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
@ -953,9 +929,7 @@ bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
#ifdef CHAT_DEBUG #ifdef CHAT_DEBUG
std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ;
@ -992,9 +966,7 @@ bool RsChatLobbyConfigItem::serialise(void *data, uint32_t& pktsize)
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef CHAT_DEBUG
std::cerr << "RsChatLobbyConfigItem::serialise() Size Error! " << std::endl; std::cerr << "RsChatLobbyConfigItem::serialise() Size Error! " << std::endl;
#endif
} }
return ok; return ok;
@ -1388,11 +1360,6 @@ RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/)
/*************************************************************************/ /*************************************************************************/
RsMsgItem::~RsMsgItem()
{
return;
}
void RsMsgItem::clear() void RsMsgItem::clear()
{ {
msgId = 0; msgId = 0;
@ -1458,7 +1425,6 @@ void RsMsgTagType::clear()
rgb_color = 0; rgb_color = 0;
} }
void RsPublicMsgInviteConfigItem::clear() void RsPublicMsgInviteConfigItem::clear()
{ {
hash.clear() ; hash.clear() ;
@ -1527,30 +1493,20 @@ std::ostream& RsMsgTags::print(std::ostream &out, uint16_t indent)
return out; return out;
} }
RsMsgTagType::~RsMsgTagType() uint32_t RsMsgItem::serial_size(bool m_bConfiguration)
{
return;
}
RsMsgTags::~RsMsgTags()
{
return;
}
uint32_t RsMsgSerialiser::sizeMsgItem(RsMsgItem *item)
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
s += 4; /* msgFlags */ s += 4; /* msgFlags */
s += 4; /* sendTime */ s += 4; /* sendTime */
s += 4; /* recvTime */ s += 4; /* recvTime */
s += GetTlvWideStringSize(item->subject); s += GetTlvWideStringSize(subject);
s += GetTlvWideStringSize(item->message); s += GetTlvWideStringSize(message);
s += item->msgto.TlvSize(); s += msgto.TlvSize();
s += item->msgcc.TlvSize(); s += msgcc.TlvSize();
s += item->msgbcc.TlvSize(); s += msgbcc.TlvSize();
s += item->attachment.TlvSize(); s += attachment.TlvSize();
if (m_bConfiguration) { if (m_bConfiguration) {
// serialise msgId too // serialise msgId too
@ -1561,19 +1517,19 @@ uint32_t RsMsgSerialiser::sizeMsgItem(RsMsgItem *item)
} }
/* serialise the data to the buffer */ /* serialise the data to the buffer */
bool RsMsgSerialiser::serialiseMsgItem(RsMsgItem *item, void *data, uint32_t *pktsize) bool RsMsgItem::serialise(void *data, uint32_t& pktsize,bool config)
{ {
uint32_t tlvsize = sizeMsgItem(item); uint32_t tlvsize = serial_size( config) ;
uint32_t offset = 0; uint32_t offset = 0;
if (*pktsize < tlvsize) if (pktsize < tlvsize)
return false; /* not enough space */ return false; /* not enough space */
*pktsize = tlvsize; pktsize = tlvsize;
bool ok = true; bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseItem() Header: " << ok << std::endl; std::cerr << "RsMsgSerialiser::serialiseItem() Header: " << ok << std::endl;
@ -1584,30 +1540,26 @@ bool RsMsgSerialiser::serialiseMsgItem(RsMsgItem *item, void *data, uint32_t
offset += 8; offset += 8;
/* add mandatory parts first */ /* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, item->msgFlags); ok &= setRawUInt32(data, tlvsize, &offset, msgFlags);
ok &= setRawUInt32(data, tlvsize, &offset, item->sendTime); ok &= setRawUInt32(data, tlvsize, &offset, sendTime);
ok &= setRawUInt32(data, tlvsize, &offset, item->recvTime); ok &= setRawUInt32(data, tlvsize, &offset, recvTime);
ok &= SetTlvWideString(data,tlvsize,&offset,TLV_TYPE_WSTR_SUBJECT,item->subject); ok &= SetTlvWideString(data,tlvsize,&offset,TLV_TYPE_WSTR_SUBJECT,subject);
ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_MSG, item->message); ok &= SetTlvWideString(data, tlvsize, &offset, TLV_TYPE_WSTR_MSG, message);
ok &= item->msgto.SetTlv(data, tlvsize, &offset); ok &= msgto.SetTlv(data, tlvsize, &offset);
ok &= item->msgcc.SetTlv(data, tlvsize, &offset); ok &= msgcc.SetTlv(data, tlvsize, &offset);
ok &= item->msgbcc.SetTlv(data, tlvsize, &offset); ok &= msgbcc.SetTlv(data, tlvsize, &offset);
ok &= item->attachment.SetTlv(data, tlvsize, &offset); ok &= attachment.SetTlv(data, tlvsize, &offset);
if (m_bConfiguration) { if (config) // serialise msgId too
// serialise msgId too ok &= setRawUInt32(data, tlvsize, &offset, msgId);
ok &= setRawUInt32(data, tlvsize, &offset, item->msgId);
}
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseItem() Size Error! " << std::endl; std::cerr << "RsMsgSerialiser::serialiseItem() Size Error! " << std::endl;
#endif
} }
return ok; return ok;
@ -1677,40 +1629,40 @@ RsMsgItem *RsMsgSerialiser::deserialiseMsgItem(void *data, uint32_t *pktsize)
return item; return item;
} }
uint32_t RsMsgSerialiser::sizePublicMsgInviteConfigItem(RsPublicMsgInviteConfigItem* item) uint32_t RsPublicMsgInviteConfigItem::serial_size(bool)
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
s += GetTlvStringSize(item->hash); s += GetTlvStringSize(hash);
s += 4; /* time_stamp */ s += 4; /* time_stamp */
return s; return s;
} }
uint32_t RsMsgSerialiser::sizeTagItem(RsMsgTagType* item) uint32_t RsMsgTagType::serial_size(bool)
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
s += GetTlvStringSize(item->text); s += GetTlvStringSize(text);
s += 4; /* color */ s += 4; /* color */
s += 4; /* tag id */ s += 4; /* tag id */
return s; return s;
} }
bool RsMsgSerialiser::serialisePublicMsgInviteConfigItem(RsPublicMsgInviteConfigItem *item, void *data, uint32_t* pktsize) bool RsPublicMsgInviteConfigItem::serialise(void *data, uint32_t& pktsize,bool config)
{ {
uint32_t tlvsize = sizePublicMsgInviteConfigItem(item); uint32_t tlvsize = serial_size(config) ;
uint32_t offset = 0; uint32_t offset = 0;
if (*pktsize < tlvsize) if (pktsize < tlvsize)
return false; /* not enough space */ return false; /* not enough space */
*pktsize = tlvsize; pktsize = tlvsize;
bool ok = true; bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl; std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl;
@ -1722,34 +1674,32 @@ bool RsMsgSerialiser::serialisePublicMsgInviteConfigItem(RsPublicMsgInviteConfig
/* add mandatory parts first */ /* add mandatory parts first */
ok &= SetTlvString(data,tlvsize,&offset, TLV_TYPE_STR_HASH_SHA1, item->hash); ok &= SetTlvString(data,tlvsize,&offset, TLV_TYPE_STR_HASH_SHA1, hash);
ok &= setRawUInt32(data,tlvsize,&offset, item->time_stamp); ok &= setRawUInt32(data,tlvsize,&offset, time_stamp);
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl; std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl;
#endif
} }
return ok; return ok;
} }
bool RsMsgSerialiser::serialiseTagItem(RsMsgTagType *item, void *data, uint32_t* pktsize) bool RsMsgTagType::serialise(void *data, uint32_t& pktsize,bool config)
{ {
uint32_t tlvsize = sizeTagItem(item); uint32_t tlvsize = serial_size( config) ;
uint32_t offset = 0; uint32_t offset = 0;
if (*pktsize < tlvsize) if (pktsize < tlvsize)
return false; /* not enough space */ return false; /* not enough space */
*pktsize = tlvsize; pktsize = tlvsize;
bool ok = true; bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl; std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl;
@ -1761,16 +1711,14 @@ bool RsMsgSerialiser::serialiseTagItem(RsMsgTagType *item, void *data, uint32_t*
/* add mandatory parts first */ /* add mandatory parts first */
ok &= SetTlvString(data,tlvsize,&offset, TLV_TYPE_STR_NAME, item->text); ok &= SetTlvString(data,tlvsize,&offset, TLV_TYPE_STR_NAME, text);
ok &= setRawUInt32(data, tlvsize, &offset, item->rgb_color); ok &= setRawUInt32(data, tlvsize, &offset, rgb_color);
ok &= setRawUInt32(data, tlvsize, &offset, item->tagId); ok &= setRawUInt32(data, tlvsize, &offset, tagId);
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl; std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl;
#endif
} }
return ok; return ok;
@ -1882,29 +1830,29 @@ RsMsgTagType* RsMsgSerialiser::deserialiseTagItem(void *data,uint32_t* pktsize)
return item; return item;
} }
uint32_t RsMsgSerialiser::sizeMsgTagItem(RsMsgTags* item) uint32_t RsMsgTags::serial_size(bool)
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
s += 4; /* msgId */ s += 4; /* msgId */
s += item->tagIds.size() * 4; /* tagIds */ s += tagIds.size() * 4; /* tagIds */
return s; return s;
} }
bool RsMsgSerialiser::serialiseMsgTagItem(RsMsgTags *item, void *data, uint32_t* pktsize) bool RsMsgTags::serialise(void *data, uint32_t& pktsize,bool config)
{ {
uint32_t tlvsize = sizeMsgTagItem(item); uint32_t tlvsize = serial_size( config) ;
uint32_t offset = 0; uint32_t offset = 0;
if (*pktsize < tlvsize) if (pktsize < tlvsize)
return false; /* not enough space */ return false; /* not enough space */
*pktsize = tlvsize; pktsize = tlvsize;
bool ok = true; bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl; std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Header: " << ok << std::endl;
@ -1914,20 +1862,16 @@ bool RsMsgSerialiser::serialiseMsgTagItem(RsMsgTags *item, void *data, uint32_t*
/* skip the header */ /* skip the header */
offset += 8; offset += 8;
ok &= setRawUInt32(data,tlvsize,&offset, item->msgId); ok &= setRawUInt32(data,tlvsize,&offset, msgId);
std::list<uint32_t>::iterator mit = item->tagIds.begin(); std::list<uint32_t>::iterator mit = tagIds.begin();
for(;mit != item->tagIds.end(); mit++) for(;mit != tagIds.end(); mit++)
{
ok &= setRawUInt32(data, tlvsize, &offset, *mit); ok &= setRawUInt32(data, tlvsize, &offset, *mit);
}
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl; std::cerr << "RsMsgSerialiser::serialiseMsgTagItem() Size Error! " << std::endl;
#endif
} }
return ok; return ok;
@ -1997,13 +1941,6 @@ RsMsgTags* RsMsgSerialiser::deserialiseMsgTagItem(void* data, uint32_t* pktsize)
/************************************** Message SrcId **********************/ /************************************** Message SrcId **********************/
RsMsgSrcId::~RsMsgSrcId()
{
return;
}
std::ostream& RsMsgSrcId::print(std::ostream& out, uint16_t indent) std::ostream& RsMsgSrcId::print(std::ostream& out, uint16_t indent)
{ {
printRsItemBase(out, "RsMsgSrcIdItem", indent); printRsItemBase(out, "RsMsgSrcIdItem", indent);
@ -2029,30 +1966,30 @@ void RsMsgSrcId::clear()
return; return;
} }
uint32_t RsMsgSerialiser::sizeMsgSrcIdItem(RsMsgSrcId* item) uint32_t RsMsgSrcId::serial_size(bool)
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
s += 4; s += 4;
s += GetTlvStringSize(item->srcId); s += GetTlvStringSize(srcId);
return s; return s;
} }
bool RsMsgSerialiser::serialiseMsgSrcIdItem(RsMsgSrcId *item, void *data, uint32_t* pktsize) bool RsMsgSrcId::serialise(void *data, uint32_t& pktsize,bool config)
{ {
uint32_t tlvsize = sizeMsgSrcIdItem(item); uint32_t tlvsize = serial_size(config) ;
uint32_t offset = 0; uint32_t offset = 0;
if (*pktsize < tlvsize) if (pktsize < tlvsize)
return false; /* not enough space */ return false; /* not enough space */
*pktsize = tlvsize; pktsize = tlvsize;
bool ok = true; bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Header: " << ok << std::endl; std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Header: " << ok << std::endl;
@ -2062,15 +1999,13 @@ bool RsMsgSerialiser::serialiseMsgSrcIdItem(RsMsgSrcId *item, void *data, uint32
/* skip the header */ /* skip the header */
offset += 8; offset += 8;
ok &= setRawUInt32(data, tlvsize, &offset, item->msgId); ok &= setRawUInt32(data, tlvsize, &offset, msgId);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, (item->srcId)); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_PEERID, srcId);
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Size Error! " << std::endl; std::cerr << "RsMsgSerialiser::serialiseMsgSrcIdItem() Size Error! " << std::endl;
#endif
} }
return ok; return ok;
@ -2132,11 +2067,6 @@ RsMsgSrcId* RsMsgSerialiser::deserialiseMsgSrcIdItem(void* data, uint32_t* pktsi
/************************************** Message ParentId **********************/ /************************************** Message ParentId **********************/
RsMsgParentId::~RsMsgParentId()
{
return;
}
std::ostream& RsMsgParentId::print(std::ostream& out, uint16_t indent) std::ostream& RsMsgParentId::print(std::ostream& out, uint16_t indent)
{ {
printRsItemBase(out, "RsMsgParentIdItem", indent); printRsItemBase(out, "RsMsgParentIdItem", indent);
@ -2162,7 +2092,7 @@ void RsMsgParentId::clear()
return; return;
} }
uint32_t RsMsgSerialiser::sizeMsgParentIdItem(RsMsgParentId* /*item*/) uint32_t RsMsgParentId::serial_size(bool)
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
@ -2172,19 +2102,19 @@ uint32_t RsMsgSerialiser::sizeMsgParentIdItem(RsMsgParentId* /*item*/)
return s; return s;
} }
bool RsMsgSerialiser::serialiseMsgParentIdItem(RsMsgParentId *item, void *data, uint32_t* pktsize) bool RsMsgParentId::serialise(void *data, uint32_t& pktsize,bool config)
{ {
uint32_t tlvsize = sizeMsgParentIdItem(item); uint32_t tlvsize = serial_size( config) ;
uint32_t offset = 0; uint32_t offset = 0;
if (*pktsize < tlvsize) if (pktsize < tlvsize)
return false; /* not enough space */ return false; /* not enough space */
*pktsize = tlvsize; pktsize = tlvsize;
bool ok = true; bool ok = true;
ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize);
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Header: " << ok << std::endl; std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Header: " << ok << std::endl;
@ -2194,15 +2124,13 @@ bool RsMsgSerialiser::serialiseMsgParentIdItem(RsMsgParentId *item, void *data,
/* skip the header */ /* skip the header */
offset += 8; offset += 8;
ok &= setRawUInt32(data, tlvsize, &offset, item->msgId); ok &= setRawUInt32(data, tlvsize, &offset, msgId);
ok &= setRawUInt32(data, tlvsize, &offset, item->msgParentId); ok &= setRawUInt32(data, tlvsize, &offset, msgParentId);
if (offset != tlvsize) if (offset != tlvsize)
{ {
ok = false; ok = false;
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Size Error! " << std::endl; std::cerr << "RsMsgSerialiser::serialiseMsgParentIdItem() Size Error! " << std::endl;
#endif
} }
return ok; return ok;
@ -2262,80 +2190,6 @@ RsMsgParentId* RsMsgSerialiser::deserialiseMsgParentIdItem(void* data, uint32_t*
/************************* end of definition of msgParentId serialisation functions ************************/ /************************* end of definition of msgParentId serialisation functions ************************/
uint32_t RsMsgSerialiser::size(RsItem *i)
{
RsMsgItem *mi;
RsMsgTagType *mtt;
RsMsgTags *mts;
RsMsgSrcId *msi;
RsMsgParentId *msp;
/* in order of frequency */
if (NULL != (mi = dynamic_cast<RsMsgItem *>(i)))
{
return sizeMsgItem(mi);
}
else if (NULL != (msi = dynamic_cast<RsMsgSrcId *>(i)))
{
return sizeMsgSrcIdItem(msi);
}
else if (NULL != (msp = dynamic_cast<RsMsgParentId *>(i)))
{
return sizeMsgParentIdItem(msp);
}
else if (NULL != (mtt = dynamic_cast<RsMsgTagType *>(i)))
{
return sizeTagItem(mtt);
}
else if (NULL != (mts = dynamic_cast<RsMsgTags *>(i)))
{
return sizeMsgTagItem(mts);
}
return 0;
}
bool RsMsgSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
{
#ifdef RSSERIAL_DEBUG
std::cerr << "RsMsgSerialiser::serialise()" << std::endl;
#endif
RsMsgItem *mi;
RsMsgSrcId* msi;
RsMsgParentId* msp;
RsMsgTagType *mtt;
RsMsgTags *mts;
RsPublicMsgInviteConfigItem *mtu;
if (NULL != (mi = dynamic_cast<RsMsgItem *>(i)))
{
return serialiseMsgItem(mi, data, pktsize);
}
else if (NULL != (msi = dynamic_cast<RsMsgSrcId *>(i)))
{
return serialiseMsgSrcIdItem(msi, data, pktsize);
}
else if (NULL != (msp = dynamic_cast<RsMsgParentId *>(i)))
{
return serialiseMsgParentIdItem(msp, data, pktsize);
}
else if (NULL != (mtt = dynamic_cast<RsMsgTagType *>(i)))
{
return serialiseTagItem(mtt, data, pktsize);
}
else if (NULL != (mts = dynamic_cast<RsMsgTags *>(i)))
{
return serialiseMsgTagItem(mts, data, pktsize);
}
else if (NULL != (mtu = dynamic_cast<RsPublicMsgInviteConfigItem *>(i)))
{
return serialisePublicMsgInviteConfigItem(mtu, data, pktsize);
}
return false;
}
RsItem* RsMsgSerialiser::deserialise(void *data, uint32_t *pktsize) RsItem* RsMsgSerialiser::deserialise(void *data, uint32_t *pktsize)
{ {
#ifdef RSSERIAL_DEBUG #ifdef RSSERIAL_DEBUG

View File

@ -432,176 +432,185 @@ const uint32_t RS_MSG_FLAGS_DISTANT = 0x00008000;
const uint32_t RS_MSG_FLAGS_SIGNATURE_CHECKS = 0x00010000; const uint32_t RS_MSG_FLAGS_SIGNATURE_CHECKS = 0x00010000;
const uint32_t RS_MSG_FLAGS_SIGNED = 0x00020000; const uint32_t RS_MSG_FLAGS_SIGNED = 0x00020000;
class RsMsgItem: public RsItem class RsMessageItem: public RsItem
{ {
public: public:
RsMsgItem() RsMessageItem(uint8_t msg_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_MSG,msg_subtype)
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG, {
RS_PKT_SUBTYPE_DEFAULT) setPriorityLevel(QOS_PRIORITY_RS_MSG_ITEM) ;
{ setPriorityLevel(QOS_PRIORITY_RS_MSG_ITEM) ; } }
RsMsgItem(uint16_t type) virtual ~RsMessageItem() {}
:RsItem(RS_PKT_VERSION_SERVICE, type, virtual void clear() {}
RS_PKT_SUBTYPE_DEFAULT) virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) = 0 ;
{ setPriorityLevel(QOS_PRIORITY_RS_MSG_ITEM) ; }
virtual ~RsMsgItem(); virtual bool serialise(void *data,uint32_t& size,bool config) = 0 ;
virtual void clear(); virtual uint32_t serial_size(bool config) = 0 ;
std::ostream &print(std::ostream &out, uint16_t indent = 0);
uint32_t msgFlags;
uint32_t msgId;
uint32_t sendTime;
uint32_t recvTime;
std::wstring subject;
std::wstring message;
RsTlvPeerIdSet msgto;
RsTlvPeerIdSet msgcc;
RsTlvPeerIdSet msgbcc;
RsTlvFileSet attachment;
}; };
class RsMsgTagType : public RsItem
class RsMsgItem: public RsMessageItem
{ {
public: public:
RsMsgTagType() RsMsgItem() :RsMessageItem(RS_PKT_SUBTYPE_DEFAULT) {}
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG,
RS_PKT_SUBTYPE_MSG_TAG_TYPE)
{ return; }
std::ostream &print(std::ostream &out, uint16_t indent = 0); // RsMsgItem(uint16_t type)
// :RsItem(RS_PKT_VERSION_SERVICE, type,
// RS_PKT_SUBTYPE_DEFAULT)
// { setPriorityLevel(QOS_PRIORITY_RS_MSG_ITEM) ; }
virtual ~RsMsgItem() {}
virtual void clear();
virtual ~RsMsgTagType(); virtual bool serialise(void *data,uint32_t& size,bool config) ;
virtual void clear(); virtual uint32_t serial_size(bool config) ;
std::string text; virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
uint32_t rgb_color;
uint32_t tagId;
// ----------- Specific fields ------------- //
uint32_t msgFlags;
uint32_t msgId;
uint32_t sendTime;
uint32_t recvTime;
std::wstring subject;
std::wstring message;
RsTlvPeerIdSet msgto;
RsTlvPeerIdSet msgcc;
RsTlvPeerIdSet msgbcc;
RsTlvFileSet attachment;
}; };
class RsMsgTags : public RsItem class RsMsgTagType : public RsMessageItem
{
public:
RsMsgTagType() :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAG_TYPE) {}
virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual bool serialise(void *data,uint32_t& size,bool config) ;
virtual uint32_t serial_size(bool config) ;
virtual ~RsMsgTagType() {}
virtual void clear();
// ----------- Specific fields ------------- //
//
std::string text;
uint32_t rgb_color;
uint32_t tagId;
};
class RsMsgTags : public RsMessageItem
{ {
public: public:
RsMsgTags() RsMsgTags()
:RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG, :RsMessageItem(RS_PKT_SUBTYPE_MSG_TAGS) {}
RS_PKT_SUBTYPE_MSG_TAGS)
{ return; }
std::ostream &print(std::ostream &out, uint16_t indent = 0); virtual bool serialise(void *data,uint32_t& size,bool config) ;
virtual uint32_t serial_size(bool config) ;
virtual ~RsMsgTags(); virtual std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual ~RsMsgTags() {}
virtual void clear(); virtual void clear();
// ----------- Specific fields ------------- //
//
uint32_t msgId; uint32_t msgId;
std::list<uint32_t> tagIds; std::list<uint32_t> tagIds;
}; };
class RsMsgSrcId : public RsItem class RsMsgSrcId : public RsMessageItem
{ {
public:
RsMsgSrcId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_SRC_TAG) {}
public: std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsMsgSrcId()
: RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG,
RS_PKT_SUBTYPE_MSG_SRC_TAG)
{ return;}
std::ostream &print(std::ostream &out, uint16_t indent = 0); virtual bool serialise(void *data,uint32_t& size,bool config) ;
virtual uint32_t serial_size(bool config) ;
virtual ~RsMsgSrcId(); virtual ~RsMsgSrcId() {}
virtual void clear(); virtual void clear();
// ----------- Specific fields ------------- //
//
uint32_t msgId; uint32_t msgId;
std::string srcId; std::string srcId;
}; };
class RsPublicMsgInviteConfigItem : public RsItem class RsPublicMsgInviteConfigItem : public RsMessageItem
{ {
public:
RsPublicMsgInviteConfigItem() : RsMessageItem(RS_PKT_SUBTYPE_MSG_INVITE) {}
public: virtual bool serialise(void *data,uint32_t& size,bool config) ;
RsPublicMsgInviteConfigItem() virtual uint32_t serial_size(bool config) ;
: RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG,
RS_PKT_SUBTYPE_MSG_INVITE)
{ return;}
std::ostream &print(std::ostream &out, uint16_t indent = 0); std::ostream &print(std::ostream &out, uint16_t indent = 0);
virtual ~RsPublicMsgInviteConfigItem() {} virtual ~RsPublicMsgInviteConfigItem() {}
virtual void clear(); virtual void clear();
std::string hash ; // ----------- Specific fields ------------- //
time_t time_stamp ; //
std::string hash ;
time_t time_stamp ;
}; };
class RsMsgParentId : public RsItem class RsMsgParentId : public RsMessageItem
{ {
public:
RsMsgParentId() : RsMessageItem(RS_PKT_SUBTYPE_MSG_PARENT_TAG) {}
public: std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsMsgParentId()
: RsItem(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG,
RS_PKT_SUBTYPE_MSG_PARENT_TAG)
{ return;}
std::ostream &print(std::ostream &out, uint16_t indent = 0); virtual bool serialise(void *data,uint32_t& size,bool config) ;
virtual uint32_t serial_size(bool config) ;
virtual ~RsMsgParentId(); virtual ~RsMsgParentId() {}
virtual void clear(); virtual void clear();
uint32_t msgId;
uint32_t msgParentId;
// ----------- Specific fields ------------- //
//
uint32_t msgId;
uint32_t msgParentId;
}; };
class RsMsgSerialiser: public RsSerialType class RsMsgSerialiser: public RsSerialType
{ {
public: public:
RsMsgSerialiser(bool bConfiguration = false) RsMsgSerialiser(bool bConfiguration = false)
:RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG), m_bConfiguration (bConfiguration) :RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_MSG), m_bConfiguration (bConfiguration) {}
{ return; }
RsMsgSerialiser(uint16_t type) RsMsgSerialiser(uint16_t type)
:RsSerialType(RS_PKT_VERSION_SERVICE, type), m_bConfiguration (false) :RsSerialType(RS_PKT_VERSION_SERVICE, type), m_bConfiguration (false) {}
{ return; }
virtual ~RsMsgSerialiser() { return; } virtual ~RsMsgSerialiser() {}
virtual uint32_t size(RsItem *); virtual uint32_t size(RsItem *item)
virtual bool serialise (RsItem *item, void *data, uint32_t *size); {
return dynamic_cast<RsMessageItem*>(item)->serial_size(m_bConfiguration) ;
}
virtual bool serialise (RsItem *item, void *data, uint32_t *size)
{
return dynamic_cast<RsMessageItem*>(item)->serialise(data,*size,m_bConfiguration) ;
}
virtual RsItem * deserialise(void *data, uint32_t *size); virtual RsItem * deserialise(void *data, uint32_t *size);
private: private:
virtual uint32_t sizeMsgItem(RsMsgItem *); virtual RsMsgItem *deserialiseMsgItem(void *data, uint32_t *size);
virtual bool serialiseMsgItem (RsMsgItem *item, void *data, uint32_t *size); virtual RsMsgTagType *deserialiseTagItem(void *data, uint32_t *size);
virtual RsMsgItem *deserialiseMsgItem(void *data, uint32_t *size); virtual RsMsgTags *deserialiseMsgTagItem(void *data, uint32_t *size);
virtual RsMsgSrcId *deserialiseMsgSrcIdItem(void *data, uint32_t *size);
virtual uint32_t sizeTagItem(RsMsgTagType *); virtual RsMsgParentId *deserialiseMsgParentIdItem(void *data, uint32_t *size);
virtual bool serialiseTagItem (RsMsgTagType *item, void *data, uint32_t *size);
virtual RsMsgTagType *deserialiseTagItem(void *data, uint32_t *size);
virtual uint32_t sizeMsgTagItem(RsMsgTags *);
virtual bool serialiseMsgTagItem (RsMsgTags *item, void *data, uint32_t *size);
virtual RsMsgTags *deserialiseMsgTagItem(void *data, uint32_t *size);
virtual uint32_t sizeMsgSrcIdItem(RsMsgSrcId *);
virtual bool serialiseMsgSrcIdItem (RsMsgSrcId *item, void *data, uint32_t *size);
virtual RsMsgSrcId *deserialiseMsgSrcIdItem(void *data, uint32_t *size);
virtual uint32_t sizeMsgParentIdItem(RsMsgParentId *);
virtual bool serialiseMsgParentIdItem (RsMsgParentId *item, void *data, uint32_t *size);
virtual RsMsgParentId *deserialiseMsgParentIdItem(void *data, uint32_t *size);
virtual uint32_t sizePublicMsgInviteConfigItem(RsPublicMsgInviteConfigItem *) ;
virtual bool serialisePublicMsgInviteConfigItem(RsPublicMsgInviteConfigItem *item, void *data, uint32_t *size);
virtual RsPublicMsgInviteConfigItem *deserialisePublicMsgInviteConfigItem(void *data, uint32_t *size); virtual RsPublicMsgInviteConfigItem *deserialisePublicMsgInviteConfigItem(void *data, uint32_t *size);
bool m_bConfiguration; // is set to true for saving configuration (enables serialising msgId) bool m_bConfiguration; // is set to true for saving configuration (enables serialising msgId)