From 8b773885fddb0a48c843effa1cbe326a34349c67 Mon Sep 17 00:00:00 2001 From: csoler Date: Wed, 5 Apr 2017 21:02:17 +0200 Subject: [PATCH] removed all chat serialization code --- libretroshare/src/chat/rschatitems.cc | 1189 ------------------------- libretroshare/src/chat/rschatitems.h | 24 - 2 files changed, 1213 deletions(-) diff --git a/libretroshare/src/chat/rschatitems.cc b/libretroshare/src/chat/rschatitems.cc index e6a405c0c..f7edf5601 100644 --- a/libretroshare/src/chat/rschatitems.cc +++ b/libretroshare/src/chat/rschatitems.cc @@ -37,196 +37,6 @@ static const uint32_t RS_CHAT_SERIALIZER_FLAGS_NO_SIGNATURE = 0x0001; -#ifdef TO_BE_REMOVED -std::ostream& RsChatMsgItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsChatMsgItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "QblogMs " << chatFlags << std::endl; - - printIndent(out, int_Indent); - out << "sendTime: " << sendTime << " (" << time(NULL)-sendTime << " secs ago)" << std::endl; - - printIndent(out, int_Indent); - - std::string cnv_message(message.begin(), message.end()); - out << "msg: " << cnv_message << std::endl; - - printRsItemEnd(out, "RsChatMsgItem", indent); - return out; -} - -std::ostream& RsChatLobbyListItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsChatLobbyListItem", indent); - - for(uint32_t i=0;i void RsTypeSerializer::serial_process(RsItem::SerializeJob j,SerializeContext& ctx,VisibleChatLobbyInfo& info,const std::string& name) { RsTypeSerializer::serial_process(j,ctx,info.id,"info.id") ; @@ -607,38 +130,6 @@ void RsChatLobbyListItem::serial_process(RsItem::SerializeJob j,SerializeContext RsTypeSerializer::serial_process(j,ctx,lobbies,"lobbies") ; } -#ifdef TO_BE_REMOVED -bool RsChatLobbyListItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - bool ok = true ; - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header! - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize ; - - uint32_t offset = 8 ; - ok &= setRawUInt32(data, tlvsize, &offset, lobbies.size()); - - for(uint32_t i=0;i(j,ctx,lobby_id,"lobby_id") ; } -#ifdef TO_BE_REMOVED -bool RsChatLobbyUnsubscribeItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - bool ok = true ; - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header! - uint32_t offset = 8 ; - - ok &= setRawUInt64(data, tlvsize, &offset, lobby_id); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } -#ifdef CHAT_DEBUG - std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; -#endif - pktsize = tlvsize ; - return ok ; -} -#endif - void RsChatLobbyConnectChallengeItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,challenge_code,"challenge_code") ; } -#ifdef TO_BE_REMOVED -bool RsChatLobbyConnectChallengeItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - bool ok = true ; - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header! - uint32_t offset = 8 ; - - ok &= setRawUInt64(data, tlvsize, &offset, challenge_code); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } -#ifdef CHAT_DEBUG - std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; -#endif - pktsize = tlvsize ; - return ok ; -} -#endif - void RsChatLobbyInviteItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobby_id,"lobby_id") ; - RsTypeSerializer::TlvString_proxy s(lobby_name,TLV_TYPE_STR_NAME) ; - RsTypeSerializer::serial_process(j,ctx,s,"lobby_name") ; RsTypeSerializer::serial_process(j,ctx,lobby_flags,"lobby_flags") ; } -#ifdef TO_BE_REMOVED -bool RsChatLobbyInviteItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - bool ok = true ; - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); // correct header! - uint32_t offset = 8 ; - - ok &= setRawUInt64(data, tlvsize, &offset, lobby_id); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, lobby_name); - ok &= setRawUInt32(data, tlvsize, &offset, lobby_flags.toUInt32()); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } -#ifdef CHAT_DEBUG - std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; -#endif - pktsize = tlvsize ; - return ok ; -} -#endif - void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { uint32_t x=0 ; @@ -838,505 +181,25 @@ void RsPrivateChatMsgConfigItem::serial_process(RsItem::SerializeJob j,Serialize RsTypeSerializer::serial_process(j,ctx,recvTime,"recvTime") ; } -#ifdef TO_BE_REMOVED -bool RsPrivateChatMsgConfigItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef CHAT_DEBUG - std::cerr << "RsChatSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsChatSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, 0); - ok &= configPeerId.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, chatFlags); - ok &= setRawUInt32(data, tlvsize, &offset, configFlags); - ok &= setRawUInt32(data, tlvsize, &offset, sendTime); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, message); - ok &= setRawUInt32(data, tlvsize, &offset, recvTime); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } - - return ok; -} - -bool RsPrivateChatDistantInviteConfigItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef CHAT_DEBUG - std::cerr << "RsChatSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsChatSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= hash.serialise(data, tlvsize, offset) ; - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_LINK, encrypted_radix64_string); - ok &= destination_pgp_id.serialise(data, tlvsize, offset); - - memcpy(&((unsigned char *)data)[offset],aes_key,16) ; - offset += 16 ; - - ok &= setRawUInt32(data, tlvsize, &offset, time_of_validity); - ok &= setRawUInt32(data, tlvsize, &offset, last_hit_time); - ok &= setRawUInt32(data, tlvsize, &offset, flags); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } - - return ok; -} -#endif - void RsChatStatusItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; - RsTypeSerializer::TlvString_proxy 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) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef CHAT_DEBUG - std::cerr << "RsChatSerialiser serialising chat status item." << std::endl; - std::cerr << "RsChatSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsChatSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, flags); - ok &= SetTlvString(data, tlvsize, &offset,TLV_TYPE_STR_MSG, status_string); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } -#ifdef CHAT_DEBUG - std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; -#endif - - return ok; -} -#endif - void RsChatAvatarItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::TlvMemBlock_proxy b(image_data,image_size) ; - RsTypeSerializer::serial_process(j,ctx,b,"image data") ; } -#ifdef TO_BE_REMOVED -bool RsChatAvatarItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef CHAT_DEBUG - std::cerr << "RsChatSerialiser serialising chat avatar item." << std::endl; - std::cerr << "RsChatSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsChatSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset,image_size); - - memcpy((void*)( (unsigned char *)data + offset),image_data,image_size) ; - offset += image_size ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatSerialiser::serialiseItem() Size Error! " << std::endl; - } -#ifdef CHAT_DEBUG - std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; -#endif - - return ok; -} -#endif - void RsChatLobbyConfigItem::serial_process(RsItem::SerializeJob j,SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,lobby_Id,"lobby_Id") ; RsTypeSerializer::serial_process(j,ctx,flags,"flags") ; } -#ifdef TO_BE_REMOVED -bool RsChatLobbyConfigItem::serialise(void *data, uint32_t& pktsize) -{ - uint32_t tlvsize = serial_size() ; - uint32_t offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, PacketId(), tlvsize); - -#ifdef CHAT_DEBUG - std::cerr << "RsChatLobbyConfigItem::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsChatLobbyConfigItem::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, lobby_Id); - ok &= setRawUInt32(data, tlvsize, &offset, flags ); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsChatLobbyConfigItem::serialise() Size Error! " << std::endl; - } - - return ok; -} - -RsChatMsgItem::RsChatMsgItem(void *data,uint32_t /*size*/,uint8_t subtype) - : RsChatItem(subtype) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - -#ifdef CHAT_DEBUG - std::cerr << "Received packet result: " ; - for(int i=0;i<20;++i) - std::cerr << (int)((uint8_t*)data)[i] << " " ; - std::cerr << std::endl ; -#endif - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &chatFlags); - ok &= getRawUInt32(data, rssize, &offset, &sendTime); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, message); - -#ifdef CHAT_DEBUG - std::cerr << "Building new chat msg item." << std::endl ; -#endif - if (getRsItemSubType(getRsItemId(data)) == RS_PKT_SUBTYPE_DEFAULT && offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; -} - -RsChatLobbyMsgItem::RsChatLobbyMsgItem(void *data,uint32_t /*size*/) - : RsChatMsgItem(data,0,RS_PKT_SUBTYPE_CHAT_LOBBY_SIGNED_MSG) -{ - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - uint32_t offset = RsChatMsgItem::serial_size() ; - - ok &= getRawUInt64(data, rssize, &offset, &parent_msg_id); - - ok &= RsChatLobbyBouncingObject::deserialise_from_memory(data,rssize,offset) ; - -#ifdef CHAT_DEBUG - std::cerr << "Building new chat lobby msg item." << std::endl ; -#endif - if (offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; -} -RsChatLobbyListRequestItem::RsChatLobbyListRequestItem(void *data,uint32_t) - : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST_REQUEST) -{ - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - uint32_t offset = 8; // skip the header - - if (offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; -} -RsChatLobbyListItem::RsChatLobbyListItem(void *data,uint32_t) - : RsChatItem(RS_PKT_SUBTYPE_CHAT_LOBBY_LIST) -{ - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - uint32_t offset = 8; // skip the header - - uint32_t n=0 ; - ok &= getRawUInt32(data, rssize, &offset, &n); - - lobbies.resize(n) ; - - for(uint32_t i=0;irecvTime = recvTime; } -#ifdef TO_BE_REMOVED -RsChatStatusItem::RsChatStatusItem(void *data,uint32_t /*size*/) - : RsChatItem(RS_PKT_SUBTYPE_CHAT_STATUS) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - -#ifdef CHAT_DEBUG - std::cerr << "Building new chat status item." << std::endl ; -#endif - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &flags); - ok &= GetTlvString(data, rssize, &offset,TLV_TYPE_STR_MSG, status_string); - - if (offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; -} - -RsChatAvatarItem::RsChatAvatarItem(void *data,uint32_t /*size*/) - : RsChatItem(RS_PKT_SUBTYPE_CHAT_AVATAR) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - -#ifdef CHAT_DEBUG - std::cerr << "Building new chat status item." << std::endl ; -#endif - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset,&image_size); - - // ensure invalid image length does not overflow data - if( (offset + image_size) <= rssize){ - image_data = new unsigned char[image_size] ; - memcpy(image_data,(void*)((unsigned char*)data+offset),image_size) ; - offset += image_size ; - }else{ - ok = false; - std::cerr << "offset+image_size exceeds rssize" << std::endl; - } - - if (offset != rssize) - std::cerr << "Size error while deserializing." << std::endl ; - if (!ok) - std::cerr << "Unknown error while deserializing." << std::endl ; -} - -#endif - uint32_t RsChatLobbyBouncingObject::serial_size_for_signature() const { SerializeContext ctx(NULL,0); diff --git a/libretroshare/src/chat/rschatitems.h b/libretroshare/src/chat/rschatitems.h index 974dda91d..7ec79ea44 100644 --- a/libretroshare/src/chat/rschatitems.h +++ b/libretroshare/src/chat/rschatitems.h @@ -327,30 +327,6 @@ class RsChatAvatarItem: public RsChatItem unsigned char *image_data ; // image }; -// This class contains the public Diffie-Hellman parameters to be sent -// when performing a DH agreement over a distant chat tunnel. -// -class RsChatDHPublicKeyItem: public RsChatItem -{ - public: - RsChatDHPublicKeyItem() :RsChatItem(RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY) {setPriorityLevel(QOS_PRIORITY_RS_CHAT_ITEM) ;} - - virtual ~RsChatDHPublicKeyItem() { BN_free(public_key) ; } - - void serial_process(RsItem::SerializeJob j,SerializeContext& ctx); - - // Private data to DH public key item - // - BIGNUM *public_key ; - - RsTlvKeySignature signature ; // signs the public key in a row. - RsTlvPublicRSAKey gxs_key ; // public key of the signer - - private: - RsChatDHPublicKeyItem(const RsChatDHPublicKeyItem&) : RsChatItem(RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY) {} // make the object non copy-able - const RsChatDHPublicKeyItem& operator=(const RsChatDHPublicKeyItem&) { return *this ;} -}; - class RsChatSerialiser: public RsSerializer { public: