mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-03-01 19:31:27 -05:00
progress in converting Chat items to new serialization model
This commit is contained in:
parent
32ce9aea3a
commit
f2fa70e395
@ -89,10 +89,10 @@ bool DistantChatService::handleOutgoingItem(RsChatItem *item)
|
|||||||
std::cerr << "p3ChatService::handleOutgoingItem(): sending to " << item->PeerId() << ": interpreted as a distant chat virtual peer id." << std::endl;
|
std::cerr << "p3ChatService::handleOutgoingItem(): sending to " << item->PeerId() << ": interpreted as a distant chat virtual peer id." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint32_t size = item->serial_size() ;
|
uint32_t size = RsChatSerialiser().size(item) ;
|
||||||
RsTemporaryMemory mem(size) ;
|
RsTemporaryMemory mem(size) ;
|
||||||
|
|
||||||
if(!item->serialise(mem,size))
|
if(!RsChatSerialiser().serialise(item,mem,size))
|
||||||
{
|
{
|
||||||
std::cerr << "(EE) serialisation error. Something's really wrong!" << std::endl;
|
std::cerr << "(EE) serialisation error. Something's really wrong!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
@ -149,10 +149,10 @@ bool DistantChatService::acceptDataFromPeer(const RsGxsId& gxs_id,const RsGxsTun
|
|||||||
|
|
||||||
// we do not use handleOutGoingItem() because there's no distant chat contact, as the chat is refused.
|
// we do not use handleOutGoingItem() because there's no distant chat contact, as the chat is refused.
|
||||||
|
|
||||||
uint32_t size = item->serial_size() ;
|
uint32_t size = RsChatSerialiser().size(item) ;
|
||||||
RsTemporaryMemory mem(size) ;
|
RsTemporaryMemory mem(size) ;
|
||||||
|
|
||||||
if(!item->serialise(mem,size))
|
if(!RsChatSerialiser().serialise(item,mem,size))
|
||||||
{
|
{
|
||||||
std::cerr << "(EE) serialisation error. Something's really wrong!" << std::endl;
|
std::cerr << "(EE) serialisation error. Something's really wrong!" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
|
@ -415,7 +415,7 @@ void DistributedChatService::checkSizeAndSendLobbyMessage(RsChatItem *msg)
|
|||||||
//
|
//
|
||||||
static const uint32_t MAX_ITEM_SIZE = 32000 ;
|
static const uint32_t MAX_ITEM_SIZE = 32000 ;
|
||||||
|
|
||||||
if(msg->serial_size() > MAX_ITEM_SIZE)
|
if(RsChatSerialiser().size(msg) > MAX_ITEM_SIZE)
|
||||||
{
|
{
|
||||||
std::cerr << "(EE) Chat item exceeds maximum serial size. It will be dropped." << std::endl;
|
std::cerr << "(EE) Chat item exceeds maximum serial size. It will be dropped." << std::endl;
|
||||||
delete msg ;
|
delete msg ;
|
||||||
|
@ -234,7 +234,6 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id)
|
|||||||
{
|
{
|
||||||
case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem() ;
|
case RS_PKT_SUBTYPE_DEFAULT: return new RsChatMsgItem() ;
|
||||||
case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem() ;
|
case RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG: return new RsPrivateChatMsgConfigItem() ;
|
||||||
case RS_PKT_SUBTYPE_DISTANT_INVITE_CONFIG: return new RsPrivateChatDistantInviteConfigItem() ;
|
|
||||||
case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem() ;
|
case RS_PKT_SUBTYPE_CHAT_STATUS: return new RsChatStatusItem() ;
|
||||||
case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem() ;
|
case RS_PKT_SUBTYPE_CHAT_AVATAR: return new RsChatAvatarItem() ;
|
||||||
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG: return new RsChatLobbyMsgItem() ;
|
case RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG: return new RsChatLobbyMsgItem() ;
|
||||||
@ -253,7 +252,7 @@ RsItem *RsChatSerialiser::create_item(uint16_t service_id,uint8_t item_sub_id)
|
|||||||
|
|
||||||
void RsChatMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
void RsChatMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
{
|
{
|
||||||
RsTypeSerializer::TlvString tt(str,TLV_TYPE_STR_MSG) ;
|
RsTypeSerializer::TlvString tt(message,TLV_TYPE_STR_MSG) ;
|
||||||
|
|
||||||
RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatflags") ;
|
RsTypeSerializer::serial_process(j,ctx,chatFlags,"chatflags") ;
|
||||||
RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ;
|
RsTypeSerializer::serial_process(j,ctx,sendTime,"sendTime") ;
|
||||||
@ -475,9 +474,9 @@ bool RsChatMsgItem::serialise(void *data, uint32_t& pktsize)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool RsChatLobbyBouncingObject::serialise_to_memory(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature)
|
void RsChatLobbyBouncingObject::serial_process_special(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature)
|
||||||
{
|
{
|
||||||
TlvString tt(nick,TLV_TYPE_STR_NAME) ;
|
RsTypeSerializer::TlvString tt(nick,TLV_TYPE_STR_NAME) ;
|
||||||
|
|
||||||
RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ;
|
RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ;
|
||||||
RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ;
|
RsTypeSerializer::serial_process(j,ctx,msg_id ,"msg_id") ;
|
||||||
@ -485,8 +484,6 @@ bool RsChatLobbyBouncingObject::serialise_to_memory(RsItem::SerializeJob j,Seria
|
|||||||
|
|
||||||
if(include_signature)
|
if(include_signature)
|
||||||
RsTypeSerializer::serial_process(j,ctx,signature,"signature") ;
|
RsTypeSerializer::serial_process(j,ctx,signature,"signature") ;
|
||||||
|
|
||||||
return true ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
@ -495,7 +492,7 @@ void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext&
|
|||||||
|
|
||||||
if(j == RsItem::SERIALIZE)
|
if(j == RsItem::SERIALIZE)
|
||||||
{
|
{
|
||||||
SerializeContext ctx2 ;
|
SerializeContext ctx2(NULL,0) ;
|
||||||
serial_process(RsItem::SIZE_ESTIMATE,ctx2);
|
serial_process(RsItem::SIZE_ESTIMATE,ctx2);
|
||||||
|
|
||||||
setRsItemHeader(ctx.mData, ctx.mSize, PacketId(), ctx2.mOffset); // correct header!
|
setRsItemHeader(ctx.mData, ctx.mSize, PacketId(), ctx2.mOffset); // correct header!
|
||||||
@ -503,7 +500,7 @@ void RsChatLobbyMsgItem::serial_process(RsItem::SerializeJob j,SerializeContext&
|
|||||||
|
|
||||||
RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ;
|
RsTypeSerializer::serial_process(j,ctx,parent_msg_id,"parent_msg_id") ;
|
||||||
|
|
||||||
ctx.mOk &= RsChatLobbyBouncingObject::serialise_to_memory(j,ctx,true) ;
|
RsChatLobbyBouncingObject::serial_process_special(j,ctx,true) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TO_BE_REMOVED
|
#ifdef TO_BE_REMOVED
|
||||||
@ -561,7 +558,7 @@ bool RsChatLobbyMsgItem::serialise_signed_part(void *data, uint32_t& pktsize)
|
|||||||
|
|
||||||
// The signature is at the end of the serialised data, so that the signed data is *before* the signature.
|
// The signature is at the end of the serialised data, so that the signed data is *before* the signature.
|
||||||
|
|
||||||
ok &= RsChatLobbyBouncingObject::serialise_to_memory(data,tlvsize,offset,false) ;
|
ok &= RsChatLobbyBouncingObject::serial_process_special(data,tlvsize,offset,false) ;
|
||||||
|
|
||||||
/* add mandatory parts first */
|
/* add mandatory parts first */
|
||||||
if (offset != tlvsize)
|
if (offset != tlvsize)
|
||||||
@ -706,6 +703,12 @@ bool RsChatLobbyEventItem::serialise_signed_part(void *data, uint32_t& pktsize)
|
|||||||
return ok ;
|
return ok ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RsChatLobbyUnsubscribeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RsTypeSerializer::serial_process<uint64_t>(j,ctx,lobby_id,"lobby_id") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TO_BE_REMOVED
|
||||||
bool RsChatLobbyUnsubscribeItem::serialise(void *data, uint32_t& pktsize)
|
bool RsChatLobbyUnsubscribeItem::serialise(void *data, uint32_t& pktsize)
|
||||||
{
|
{
|
||||||
uint32_t tlvsize = serial_size() ;
|
uint32_t tlvsize = serial_size() ;
|
||||||
@ -730,6 +733,14 @@ bool RsChatLobbyUnsubscribeItem::serialise(void *data, uint32_t& pktsize)
|
|||||||
pktsize = tlvsize ;
|
pktsize = tlvsize ;
|
||||||
return ok ;
|
return ok ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void RsChatLobbyConnectChallengeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RsTypeSerializer::serial_process<uint64_t>(j,ctx,challenge_code,"challenge_code") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TO_BE_REMOVED
|
||||||
bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize)
|
bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize)
|
||||||
{
|
{
|
||||||
uint32_t tlvsize = serial_size() ;
|
uint32_t tlvsize = serial_size() ;
|
||||||
@ -754,7 +765,19 @@ bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize)
|
|||||||
pktsize = tlvsize ;
|
pktsize = tlvsize ;
|
||||||
return ok ;
|
return ok ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RsTypeSerializer::serial_process<uint64_t>(j,ctx,lobby_id,"lobby_id") ;
|
||||||
|
|
||||||
|
TlvString s(message,TLV_TYPE_STR_NAME) ;
|
||||||
|
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,s,"lobby_name") ;
|
||||||
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,lobby_flags.toUInt32(),"lobby_flags") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TO_BE_REMOVED
|
||||||
bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize)
|
bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize)
|
||||||
{
|
{
|
||||||
uint32_t tlvsize = serial_size() ;
|
uint32_t tlvsize = serial_size() ;
|
||||||
@ -781,7 +804,22 @@ bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize)
|
|||||||
pktsize = tlvsize ;
|
pktsize = tlvsize ;
|
||||||
return ok ;
|
return ok ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
uint32_t x=0 ;
|
||||||
|
TlvString s(message,TLV_TYPE_STR_MSG) ;
|
||||||
|
|
||||||
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,x,"place holder value") ;
|
||||||
|
RsTypeSerializer::serial_process (j,ctx,configPeerId,"configPeerId") ;
|
||||||
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,chatFlags,"chatFlags") ;
|
||||||
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,sendTime,"sendTime") ;
|
||||||
|
RsTypeSerializer::serial_process (j,ctx,s,"message") ;
|
||||||
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,recvTime,"recvTime") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TO_BE_REMOVED
|
||||||
bool RsPrivateChatMsgConfigItem::serialise(void *data, uint32_t& pktsize)
|
bool RsPrivateChatMsgConfigItem::serialise(void *data, uint32_t& pktsize)
|
||||||
{
|
{
|
||||||
uint32_t tlvsize = serial_size() ;
|
uint32_t tlvsize = serial_size() ;
|
||||||
@ -821,6 +859,7 @@ bool RsPrivateChatMsgConfigItem::serialise(void *data, uint32_t& pktsize)
|
|||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsize)
|
bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsize)
|
||||||
{
|
{
|
||||||
uint32_t tlvsize = serial_size() ;
|
uint32_t tlvsize = serial_size() ;
|
||||||
@ -863,6 +902,18 @@ bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsi
|
|||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags,"flags") ;
|
||||||
|
|
||||||
|
RsTypeSerializer::TlvString tt(status_string,TLV_TYPE_STR_MSG) ;
|
||||||
|
|
||||||
|
RsTypeSerializer::serial_process(j,ctx,tt,"status_string") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TO_BE_REMOVED
|
||||||
bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize)
|
bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize)
|
||||||
{
|
{
|
||||||
uint32_t tlvsize = serial_size() ;
|
uint32_t tlvsize = serial_size() ;
|
||||||
@ -901,7 +952,14 @@ bool RsChatStatusItem::serialise(void *data, uint32_t& pktsize)
|
|||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void RsChatAvatarItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RsTypeSerializer::serial_process<RsTypeSerializer::BinaryDataBlock>(j,ctx,RsTypeSerializer::BinaryDataBlock(data,image_size)) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TO_BE_REMOVED
|
||||||
bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize)
|
bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize)
|
||||||
{
|
{
|
||||||
uint32_t tlvsize = serial_size() ;
|
uint32_t tlvsize = serial_size() ;
|
||||||
@ -942,6 +1000,15 @@ bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize)
|
|||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void RsChatLobbyConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx)
|
||||||
|
{
|
||||||
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,lobby_Id,"lobby_Id") ;
|
||||||
|
RsTypeSerializer::serial_process<uint32_t>(j,ctx,flags,"flags") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TO_BE_REMOVED
|
||||||
bool RsChatLobbyConfigItem::serialise(void *data, uint32_t& pktsize)
|
bool RsChatLobbyConfigItem::serialise(void *data, uint32_t& pktsize)
|
||||||
{
|
{
|
||||||
uint32_t tlvsize = serial_size() ;
|
uint32_t tlvsize = serial_size() ;
|
||||||
@ -1067,6 +1134,7 @@ RsChatLobbyListItem::RsChatLobbyListItem(void *data,uint32_t)
|
|||||||
if (!ok)
|
if (!ok)
|
||||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
bool RsChatLobbyBouncingObject::deserialise_from_memory(void *data,uint32_t rssize,uint32_t& offset)
|
bool RsChatLobbyBouncingObject::deserialise_from_memory(void *data,uint32_t rssize,uint32_t& offset)
|
||||||
{
|
{
|
||||||
@ -1103,6 +1171,8 @@ RsChatLobbyEventItem::RsChatLobbyEventItem(void *data,uint32_t /*size*/)
|
|||||||
if (!ok)
|
if (!ok)
|
||||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TO_BE_REMOVED
|
||||||
RsChatLobbyUnsubscribeItem::RsChatLobbyUnsubscribeItem(void *data,uint32_t /*size*/)
|
RsChatLobbyUnsubscribeItem::RsChatLobbyUnsubscribeItem(void *data,uint32_t /*size*/)
|
||||||
: RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE)
|
: RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE)
|
||||||
{
|
{
|
||||||
@ -1246,6 +1316,7 @@ RsChatLobbyConfigItem::RsChatLobbyConfigItem(void *data,uint32_t /*size*/)
|
|||||||
if (!ok)
|
if (!ok)
|
||||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */
|
/* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */
|
||||||
void RsPrivateChatMsgConfigItem::set(RsChatMsgItem *ci, const RsPeerId& /*peerId*/, uint32_t confFlags)
|
void RsPrivateChatMsgConfigItem::set(RsChatMsgItem *ci, const RsPeerId& /*peerId*/, uint32_t confFlags)
|
||||||
@ -1270,6 +1341,7 @@ void RsPrivateChatMsgConfigItem::get(RsChatMsgItem *ci)
|
|||||||
ci->recvTime = recvTime;
|
ci->recvTime = recvTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TO_BE_REMOVED
|
||||||
RsChatStatusItem::RsChatStatusItem(void *data,uint32_t /*size*/)
|
RsChatStatusItem::RsChatStatusItem(void *data,uint32_t /*size*/)
|
||||||
: RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS)
|
: RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS)
|
||||||
{
|
{
|
||||||
@ -1319,4 +1391,5 @@ RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/)
|
|||||||
std::cerr << "Unknown error while deserializing." << std::endl ;
|
std::cerr << "Unknown error while deserializing." << std::endl ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ const uint8_t RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE = 0x1A ;
|
|||||||
|
|
||||||
typedef uint64_t ChatLobbyId ;
|
typedef uint64_t ChatLobbyId ;
|
||||||
typedef uint64_t ChatLobbyMsgId ;
|
typedef uint64_t ChatLobbyMsgId ;
|
||||||
typedef std::string ChatLobbyNickName ;
|
typedef std::string ChatLobbyNickName ;
|
||||||
typedef uint64_t DistantChatDHSessionId ;
|
typedef uint64_t DistantChatDHSessionId ;
|
||||||
|
|
||||||
class RsChatItem: public RsItem
|
class RsChatItem: public RsItem
|
||||||
@ -91,7 +91,7 @@ class RsChatItem: public RsItem
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual ~RsChatItem() {}
|
virtual ~RsChatItem() {}
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) {} // derived from RsItem, but should be removed
|
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0) { return out; } // derived from RsItem, but should be removed
|
||||||
|
|
||||||
virtual void clear() {}
|
virtual void clear() {}
|
||||||
};
|
};
|
||||||
@ -136,7 +136,6 @@ public:
|
|||||||
RsTlvKeySignature signature ;
|
RsTlvKeySignature signature ;
|
||||||
|
|
||||||
virtual RsChatLobbyBouncingObject *duplicate() const = 0 ;
|
virtual RsChatLobbyBouncingObject *duplicate() const = 0 ;
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
|
||||||
// returns the size in bytes of the data chunk to sign.
|
// returns the size in bytes of the data chunk to sign.
|
||||||
|
|
||||||
@ -148,9 +147,7 @@ protected:
|
|||||||
// They are called by serial_size() and serialise() from children, but should not overload the serial_size() and
|
// 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.
|
// serialise() methods, otherwise the wrong method will be called when serialising from this top level class.
|
||||||
|
|
||||||
uint32_t serialized_size(bool include_signature) ;
|
void serial_process_special(RsItem::SerializeJob j,SerializeContext& ctx,bool include_signature);
|
||||||
bool serialise_to_memory(RsItem::SerializeJob j, SerializeContext &ctx, bool include_signature) ;
|
|
||||||
bool deserialise_from_memory(void *data,uint32_t rssize,uint32_t& offset) ;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsChatLobbyMsgItem: public RsChatMsgItem, public RsChatLobbyBouncingObject
|
class RsChatLobbyMsgItem: public RsChatMsgItem, public RsChatLobbyBouncingObject
|
||||||
@ -158,14 +155,10 @@ class RsChatLobbyMsgItem: public RsChatMsgItem, public RsChatLobbyBouncingObject
|
|||||||
public:
|
public:
|
||||||
RsChatLobbyMsgItem() :RsChatMsgItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG) {}
|
RsChatLobbyMsgItem() :RsChatMsgItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG) {}
|
||||||
|
|
||||||
RsChatLobbyMsgItem(void *data,uint32_t size) ; // deserialization /// TODO!!!
|
|
||||||
|
|
||||||
virtual ~RsChatLobbyMsgItem() {}
|
virtual ~RsChatLobbyMsgItem() {}
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; }
|
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyMsgItem(*this) ; }
|
||||||
|
|
||||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx) ;
|
||||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
|
||||||
|
|
||||||
virtual uint32_t signed_serial_size() ;
|
virtual uint32_t signed_serial_size() ;
|
||||||
virtual bool serialise_signed_part(void *data,uint32_t& size) ;// Isn't it better that items can serialize themselves ?
|
virtual bool serialise_signed_part(void *data,uint32_t& size) ;// Isn't it better that items can serialize themselves ?
|
||||||
@ -177,17 +170,14 @@ class RsChatLobbyEventItem: public RsChatItem, public RsChatLobbyBouncingObject
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsChatLobbyEventItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT) {}
|
RsChatLobbyEventItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_EVENT) {}
|
||||||
RsChatLobbyEventItem(void *data,uint32_t size) ; // deserialization /// TODO!!!
|
|
||||||
|
|
||||||
virtual ~RsChatLobbyEventItem() {}
|
virtual ~RsChatLobbyEventItem() {}
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; }
|
virtual RsChatLobbyBouncingObject *duplicate() const { return new RsChatLobbyEventItem(*this) ; }
|
||||||
//
|
//
|
||||||
virtual bool serialise(void *data,uint32_t& size) ;
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
||||||
virtual uint32_t serial_size() ;
|
|
||||||
|
|
||||||
virtual uint32_t signed_serial_size() ;
|
virtual uint32_t signed_serial_size() ;
|
||||||
virtual bool serialise_signed_part(void *data,uint32_t& size) ;
|
virtual bool serialise_signed_part(void *data,uint32_t& size) ;
|
||||||
|
|
||||||
// members.
|
// members.
|
||||||
//
|
//
|
||||||
@ -200,13 +190,9 @@ class RsChatLobbyListRequestItem: public RsChatItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsChatLobbyListRequestItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST) {}
|
RsChatLobbyListRequestItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST) {}
|
||||||
RsChatLobbyListRequestItem(void *data,uint32_t size) ;
|
|
||||||
virtual ~RsChatLobbyListRequestItem() {}
|
virtual ~RsChatLobbyListRequestItem() {}
|
||||||
|
|
||||||
virtual bool serialise(void *data,uint32_t& size) ;
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
||||||
virtual uint32_t serial_size() ;
|
|
||||||
|
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VisibleChatLobbyInfo
|
struct VisibleChatLobbyInfo
|
||||||
@ -222,13 +208,9 @@ class RsChatLobbyListItem: public RsChatItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsChatLobbyListItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST) {}
|
RsChatLobbyListItem() : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST) {}
|
||||||
RsChatLobbyListItem(void *data,uint32_t size) ;
|
|
||||||
virtual ~RsChatLobbyListItem() {}
|
virtual ~RsChatLobbyListItem() {}
|
||||||
|
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
||||||
|
|
||||||
virtual bool serialise(void *data,uint32_t& size) ;
|
|
||||||
virtual uint32_t serial_size() ;
|
|
||||||
|
|
||||||
std::vector<VisibleChatLobbyInfo> lobbies ;
|
std::vector<VisibleChatLobbyInfo> lobbies ;
|
||||||
};
|
};
|
||||||
@ -237,48 +219,38 @@ class RsChatLobbyUnsubscribeItem: public RsChatItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsChatLobbyUnsubscribeItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE) {}
|
RsChatLobbyUnsubscribeItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_UNSUBSCRIBE) {}
|
||||||
RsChatLobbyUnsubscribeItem(void *data,uint32_t size) ; // deserialization
|
|
||||||
|
|
||||||
virtual ~RsChatLobbyUnsubscribeItem() {}
|
virtual ~RsChatLobbyUnsubscribeItem() {}
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
||||||
|
|
||||||
uint64_t lobby_id ;
|
uint64_t lobby_id ;
|
||||||
|
|
||||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
|
||||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsChatLobbyConnectChallengeItem: public RsChatItem
|
class RsChatLobbyConnectChallengeItem: public RsChatItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsChatLobbyConnectChallengeItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE) {}
|
RsChatLobbyConnectChallengeItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CHALLENGE) {}
|
||||||
RsChatLobbyConnectChallengeItem(void *data,uint32_t size) ; // deserialization
|
|
||||||
|
|
||||||
virtual ~RsChatLobbyConnectChallengeItem() {}
|
virtual ~RsChatLobbyConnectChallengeItem() {}
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
||||||
|
|
||||||
uint64_t challenge_code ;
|
uint64_t challenge_code ;
|
||||||
|
|
||||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
|
||||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RsChatLobbyInviteItem: public RsChatItem
|
class RsChatLobbyInviteItem: public RsChatItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsChatLobbyInviteItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE) {}
|
RsChatLobbyInviteItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_INVITE) {}
|
||||||
RsChatLobbyInviteItem(void *data,uint32_t size) ; // deserialization
|
|
||||||
|
|
||||||
virtual ~RsChatLobbyInviteItem() {}
|
virtual ~RsChatLobbyInviteItem() {}
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
||||||
|
|
||||||
ChatLobbyId lobby_id ;
|
ChatLobbyId lobby_id ;
|
||||||
std::string lobby_name ;
|
std::string lobby_name ;
|
||||||
std::string lobby_topic ;
|
std::string lobby_topic ;
|
||||||
ChatLobbyFlags lobby_flags ;
|
ChatLobbyFlags lobby_flags ;
|
||||||
|
|
||||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
|
||||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -289,14 +261,11 @@ class RsPrivateChatMsgConfigItem: public RsChatItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsPrivateChatMsgConfigItem() :RsChatItem(RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG) {}
|
RsPrivateChatMsgConfigItem() :RsChatItem(RS_PKT_SUBTYPE_PRIVATECHATMSG_CONFIG) {}
|
||||||
RsPrivateChatMsgConfigItem(void *data,uint32_t size) ; // deserialization
|
|
||||||
|
|
||||||
virtual ~RsPrivateChatMsgConfigItem() {}
|
virtual ~RsPrivateChatMsgConfigItem() {}
|
||||||
virtual void clear() {}
|
virtual void clear() {}
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
|
||||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
||||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
|
||||||
|
|
||||||
/* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */
|
/* set data from RsChatMsgItem to RsPrivateChatMsgConfigItem */
|
||||||
void set(RsChatMsgItem *ci, const RsPeerId &peerId, uint32_t confFlags);
|
void set(RsChatMsgItem *ci, const RsPeerId &peerId, uint32_t confFlags);
|
||||||
@ -310,43 +279,19 @@ class RsPrivateChatMsgConfigItem: public RsChatItem
|
|||||||
std::string message;
|
std::string message;
|
||||||
uint32_t recvTime;
|
uint32_t recvTime;
|
||||||
};
|
};
|
||||||
class RsPrivateChatDistantInviteConfigItem: public RsChatItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RsPrivateChatDistantInviteConfigItem() :RsChatItem(RS_PKT_SUBTYPE_DISTANT_INVITE_CONFIG) {}
|
|
||||||
RsPrivateChatDistantInviteConfigItem(void *data,uint32_t size) ; // deserialization
|
|
||||||
|
|
||||||
virtual ~RsPrivateChatDistantInviteConfigItem() {}
|
|
||||||
virtual void clear() {}
|
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
|
||||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
|
||||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
|
||||||
|
|
||||||
unsigned char aes_key[16] ;
|
|
||||||
RsFileHash hash ;
|
|
||||||
std::string encrypted_radix64_string ;
|
|
||||||
RsPgpId destination_pgp_id ;
|
|
||||||
uint32_t time_of_validity ;
|
|
||||||
uint32_t last_hit_time ;
|
|
||||||
uint32_t flags ;
|
|
||||||
};
|
|
||||||
class RsChatLobbyConfigItem: public RsChatItem
|
class RsChatLobbyConfigItem: public RsChatItem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsChatLobbyConfigItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG) { lobby_Id = 0; }
|
RsChatLobbyConfigItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_CONFIG) { lobby_Id = 0; }
|
||||||
RsChatLobbyConfigItem(void *data,uint32_t size) ; // deserialization
|
|
||||||
|
|
||||||
virtual ~RsChatLobbyConfigItem() {}
|
virtual ~RsChatLobbyConfigItem() {}
|
||||||
|
|
||||||
virtual void clear() { lobby_Id = 0; }
|
virtual void clear() { lobby_Id = 0; }
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
|
||||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
||||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
|
||||||
|
|
||||||
uint64_t lobby_Id;
|
uint64_t lobby_Id;
|
||||||
uint32_t flags ;
|
uint32_t flags ;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This class contains activity info for the sending peer: active, idle, typing, etc.
|
// This class contains activity info for the sending peer: active, idle, typing, etc.
|
||||||
@ -355,13 +300,10 @@ class RsChatStatusItem: public RsChatItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsChatStatusItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS) {}
|
RsChatStatusItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS) {}
|
||||||
RsChatStatusItem(void *data,uint32_t size) ; // deserialization
|
|
||||||
|
|
||||||
virtual ~RsChatStatusItem() {}
|
virtual ~RsChatStatusItem() {}
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
|
||||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
||||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
|
||||||
|
|
||||||
uint32_t flags ;
|
uint32_t flags ;
|
||||||
std::string status_string;
|
std::string status_string;
|
||||||
@ -373,13 +315,9 @@ class RsChatAvatarItem: public RsChatItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsChatAvatarItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_AVATAR_ITEM) ;}
|
RsChatAvatarItem() :RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_AVATAR_ITEM) ;}
|
||||||
RsChatAvatarItem(void *data,uint32_t size) ; // deserialization
|
|
||||||
|
|
||||||
virtual ~RsChatAvatarItem() ;
|
virtual ~RsChatAvatarItem() ;
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
||||||
|
|
||||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
|
||||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
|
||||||
|
|
||||||
uint32_t image_size ; // size of data in bytes
|
uint32_t image_size ; // size of data in bytes
|
||||||
unsigned char *image_data ; // image
|
unsigned char *image_data ; // image
|
||||||
@ -392,13 +330,10 @@ class RsChatDHPublicKeyItem: public RsChatItem
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RsChatDHPublicKeyItem() :RsChatItem(RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_ITEM) ;}
|
RsChatDHPublicKeyItem() :RsChatItem(RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_ITEM) ;}
|
||||||
RsChatDHPublicKeyItem(void *data,uint32_t size) ; // deserialization
|
|
||||||
|
|
||||||
virtual ~RsChatDHPublicKeyItem() { BN_free(public_key) ; }
|
virtual ~RsChatDHPublicKeyItem() { BN_free(public_key) ; }
|
||||||
virtual std::ostream& print(std::ostream &out, uint16_t indent = 0);
|
|
||||||
|
|
||||||
virtual bool serialise(void *data,uint32_t& size) ; // Isn't it better that items can serialize themselves ?
|
void serial_process(RsItem::SerializeJob j,SerializeContext& ctx);
|
||||||
virtual uint32_t serial_size() ; // deserialise is handled using a constructor
|
|
||||||
|
|
||||||
// Private data to DH public key item
|
// Private data to DH public key item
|
||||||
//
|
//
|
||||||
|
@ -9,19 +9,6 @@
|
|||||||
|
|
||||||
#define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : "
|
#define SERIALIZE_ERROR() std::cerr << __PRETTY_FUNCTION__ << " : "
|
||||||
|
|
||||||
class SerializeContext
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
SerializeContext(uint8_t *data,uint32_t size)
|
|
||||||
: mData(data),mSize(size),mOffset(0),mOk(true) {}
|
|
||||||
|
|
||||||
unsigned char *mData ;
|
|
||||||
uint32_t mSize ;
|
|
||||||
uint32_t mOffset ;
|
|
||||||
bool mOk ;
|
|
||||||
};
|
|
||||||
|
|
||||||
class RsSerializer: public RsSerialType
|
class RsSerializer: public RsSerialType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -1,6 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include "serialiser/rsserial.h"
|
#include "serialiser/rsserial.h"
|
||||||
#include "serialiser/rstlvbase.h"
|
#include "serialiser/rstlvbase.h"
|
||||||
|
|
||||||
|
class SerializeContext
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
SerializeContext(uint8_t *data,uint32_t size)
|
||||||
|
: mData(data),mSize(size),mOffset(0),mOk(true) {}
|
||||||
|
|
||||||
|
unsigned char *mData ;
|
||||||
|
uint32_t mSize ;
|
||||||
|
uint32_t mOffset ;
|
||||||
|
bool mOk ;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class RsTypeSerializer
|
class RsTypeSerializer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -8,6 +24,15 @@ class RsTypeSerializer
|
|||||||
|
|
||||||
typedef std::pair<std::string&,uint16_t> TlvString;
|
typedef std::pair<std::string&,uint16_t> TlvString;
|
||||||
|
|
||||||
|
class BinaryDataBlock_ref
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BinaryDataBlock_ref(unsigned char *& _mem,uint32_t& _size) : mem(&_mem),size(&_size){}
|
||||||
|
|
||||||
|
unsigned char **mem ;
|
||||||
|
uint32_t *size ;
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member,const std::string& member_name)
|
static void serial_process(RsItem::SerializeJob j,SerializeContext& ctx,T& member,const std::string& member_name)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user