fixed a few bugs in chat serialization

This commit is contained in:
csoler 2017-04-05 20:49:32 +02:00
parent 03c31ceacc
commit ae9d0b2ab4
3 changed files with 43 additions and 28 deletions

View File

@ -222,7 +222,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const
mGixs->requestKey(obj->signature.keyId,peer_list,RsIdentityUsage(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id));
uint32_t size = obj->serial_size_no_signature() ;
uint32_t size = obj->serial_size_for_signature() ;
RsTemporaryMemory memory(size) ;
#ifdef DEBUG_CHAT_LOBBIES
@ -230,7 +230,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const
std::cerr << " signature id: " << obj->signature.keyId << std::endl;
#endif
if(!obj->serialize_no_signature(memory,size))
if(!obj->serialize_for_signature(memory,size))
{
std::cerr << " (EE) Cannot serialise message item. " << std::endl;
return false ;
@ -239,7 +239,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const
uint32_t error_status ;
RsIdentityUsage use_info(RS_SERVICE_TYPE_CHAT,RsIdentityUsage::CHAT_LOBBY_MSG_VALIDATION,RsGxsGroupId(),RsGxsMessageId(),obj->lobby_id) ;
if(!mGixs->validateData(memory,obj->serial_size_no_signature(),obj->signature,false,use_info,error_status))
if(!mGixs->validateData(memory,obj->serial_size_for_signature(),obj->signature,false,use_info,error_status))
{
bool res = false ;
@ -970,10 +970,10 @@ bool DistributedChatService::locked_initLobbyBouncableObject(const ChatLobbyId&
// now sign the object, if the lobby expects it
uint32_t size = item.serial_size_no_signature() ;
uint32_t size = item.serial_size_for_signature() ;
RsTemporaryMemory memory(size) ;
if(!item.serialize_no_signature(memory,size))
if(!item.serialize_for_signature(memory,size))
{
std::cerr << "(EE) Cannot sign message item. " << std::endl;
return false ;

View File

@ -491,12 +491,15 @@ void RsChatLobbyBouncingObject::serial_process(RsItem::SerializeJob j, Serialize
void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsChatMsgItem::serial_process(j,ctx) ;
RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ;
RsChatLobbyBouncingObject::serial_process(j,ctx,true) ;
}
void RsChatLobbyMsgItem::serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsChatMsgItem::serial_process(j,ctx) ;
RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ;
RsChatLobbyBouncingObject::serial_process(j,ctx,false) ;
}
#ifdef TO_BE_REMOVED
/* serialise the data to the buffer */
bool RsChatLobbyMsgItem::serialise(void *data, uint32_t& pktsize)
@ -646,7 +649,16 @@ void RsChatLobbyEventItem::serial_process(RsItem::SerializeJob j,SerializeContex
RsChatLobbyBouncingObject::serial_process(j,ctx,true) ;
}
void RsChatLobbyEventItem::serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx)
{
RsTypeSerializer::TlvString_proxy tt(string1,TLV_TYPE_STR_NAME) ;
RsTypeSerializer::serial_process<uint8_t>(j,ctx,event_type,"event_type") ;
RsTypeSerializer::serial_process (j,ctx,tt ,"string1") ;
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime ,"sendTime") ;
RsChatLobbyBouncingObject::serial_process(j,ctx,false) ;
}
#ifdef TO_BE_REMOVED
bool RsChatLobbyEventItem::serialise(void *data, uint32_t& pktsize)
{
@ -1400,22 +1412,22 @@ RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/)
#endif
uint32_t RsChatLobbyBouncingObject::serial_size_no_signature() const
uint32_t RsChatLobbyBouncingObject::serial_size_for_signature() const
{
SerializeContext ctx(NULL,0);
ctx.mOffset = 8;
const_cast<RsChatLobbyBouncingObject*>(this)->serial_process(RsItem::SERIALIZE,ctx,false) ;
const_cast<RsChatLobbyBouncingObject*>(this)->serial_process_for_signature(RsItem::SIZE_ESTIMATE,ctx) ;
return ctx.mOffset ;
}
bool RsChatLobbyBouncingObject::serialize_no_signature(uint8_t *data,uint32_t size) const
bool RsChatLobbyBouncingObject::serialize_for_signature(uint8_t *data,uint32_t size) const
{
SerializeContext ctx(data,0);
uint32_t tlvsize = serial_size_no_signature() ;
uint32_t tlvsize = serial_size_for_signature() ;
if(tlvsize > size)
throw std::runtime_error("Cannot serialise: not enough room.") ;
@ -1428,7 +1440,7 @@ bool RsChatLobbyBouncingObject::serialize_no_signature(uint8_t *data,uint32_t si
ctx.mOffset = 8;
ctx.mSize = tlvsize;
const_cast<RsChatLobbyBouncingObject*>(this)->serial_process(RsItem::SERIALIZE,ctx,false) ;
const_cast<RsChatLobbyBouncingObject*>(this)->serial_process_for_signature(RsItem::SERIALIZE,ctx) ;
if(ctx.mSize != ctx.mOffset)
{

View File

@ -137,15 +137,16 @@ public:
virtual RsChatLobbyBouncingObject *duplicate() const = 0 ;
uint32_t serial_size_no_signature() const ;
bool serialize_no_signature(uint8_t *data,uint32_t size) const ;
uint32_t serial_size_for_signature() const ;
bool serialize_for_signature(uint8_t *data,uint32_t size) const ;
protected:
// The functions below handle the serialisation of data that is specific to the bouncing object level.
// They are called by serial_size() and serialise() from children, but should not overload the serial_size() and
// serialise() methods, otherwise the wrong method will be called when serialising from this top level class.
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature);
virtual void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature);
virtual void serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx)=0;
virtual uint32_t PacketId() const= 0;
};
@ -159,6 +160,7 @@ public:
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; }
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx) ;
void serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) ; // This one is new, and used to add/remove signature on demand
ChatLobbyMsgId parent_msg_id ; // Used for threaded chat.
@ -168,22 +170,23 @@ protected:
class RsChatLobbyEventItem: public RsChatItem, public RsChatLobbyBouncingObject
{
public:
RsChatLobbyEventItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT) {}
public:
RsChatLobbyEventItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT) {}
virtual ~RsChatLobbyEventItem() {}
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; }
//
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
virtual ~RsChatLobbyEventItem() {}
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; }
//
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
void serial_process_for_signature(RsItem::SerializeJob j,SerializeContext& ctx) ; // This one is new, and used to add/remove signature on demand
// members.
//
uint8_t event_type ; // used for defining the type of event.
std::string string1; // used for any string
uint32_t sendTime; // used to check for old looping messages
// members.
//
uint8_t event_type ; // used for defining the type of event.
std::string string1; // used for any string
uint32_t sendTime; // used to check for old looping messages
protected:
virtual uint32_t PacketId() const { return RsChatItem::PacketId() ; }
virtual uint32_t PacketId() const { return RsChatItem::PacketId() ; }
};
class RsChatLobbyListRequestItem: public RsChatItem