diff --git a/libretroshare/src/grouter/grouteritems.cc b/libretroshare/src/grouter/grouteritems.cc index c856132db..5fc4813a7 100644 --- a/libretroshare/src/grouter/grouteritems.cc +++ b/libretroshare/src/grouter/grouteritems.cc @@ -67,81 +67,11 @@ void RsGRouterTransactionChunkItem::serial_process(RsGenericSerializer::Serializ std::cerr << " [Binary data] " << ", length=" << chunk_size << " data=" << RsUtil::BinToHex((uint8_t*)chunk_data,std::min(50u,chunk_size)) << ((chunk_size>50)?"...":"") << std::endl; } -#ifdef TO_REMOVE -RsGRouterTransactionChunkItem *RsGRouterSerialiser::deserialise_RsGRouterTransactionChunkItem(void *data, uint32_t tlvsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - if(tlvsize < rssize) - { - std::cerr << __PRETTY_FUNCTION__ << ": wrong encoding of item size. Serialisation error!" << std::endl; - return NULL ; - } - - RsGRouterTransactionChunkItem *item = new RsGRouterTransactionChunkItem() ; - - /* add mandatory parts first */ - ok &= getRawUInt64(data, tlvsize, &offset, &item->propagation_id); - ok &= getRawUInt32(data, tlvsize, &offset, &item->chunk_start); - ok &= getRawUInt32(data, tlvsize, &offset, &item->chunk_size); - ok &= getRawUInt32(data, tlvsize, &offset, &item->total_size); - - if(item->chunk_size > rssize || offset > rssize - item->chunk_size) // better than if(item->chunk_size + offset > rssize) - { - std::cerr << __PRETTY_FUNCTION__ << ": Cannot read beyond item size. Serialisation error!" << std::endl; - delete item; - return NULL ; - } - if( NULL == (item->chunk_data = (uint8_t*)rs_malloc(item->chunk_size))) - { - delete item; - return NULL ; - } - - memcpy(item->chunk_data,&((uint8_t*)data)[offset],item->chunk_size) ; - offset += item->chunk_size ; - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterTransactionAcknItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,propagation_id,"propagation_id") ; } -#ifdef TO_REMOVE -RsGRouterTransactionAcknItem *RsGRouterSerialiser::deserialise_RsGRouterTransactionAcknItem(void *data, uint32_t tlvsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGRouterTransactionAcknItem *item = new RsGRouterTransactionAcknItem() ; - - /* add mandatory parts first */ - ok &= getRawUInt64(data, tlvsize, &offset, &item->propagation_id); - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterGenericDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,routing_id,"routing_id") ; @@ -174,76 +104,6 @@ void RsGRouterGenericDataItem::serial_process(RsGenericSerializer::SerializeJob } } -#ifdef TO_REMOVE -RsGRouterGenericDataItem *RsGRouterSerialiser::deserialise_RsGRouterGenericDataItem(void *data, uint32_t pktsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - if(pktsize < rssize) - { - std::cerr << __PRETTY_FUNCTION__ << ": wrong encoding of item size. Serialisation error!" << std::endl; - return NULL ; - } - RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem() ; - - ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id); - ok &= item->destination_key.deserialise(data, pktsize, offset) ; - ok &= getRawUInt32(data, pktsize, &offset, &item->service_id); - ok &= getRawUInt32(data, pktsize, &offset, &item->data_size); - - if(item->data_size > 0) // This happens when the item data has been deleted from the cache - { - if(item->data_size > rssize || offset > rssize - item->data_size) // better than if(item->data_size + offset > rssize) - { - std::cerr << __PRETTY_FUNCTION__ << ": Cannot read beyond item size. Serialisation error!" << std::endl; - delete item; - return NULL ; - } - - if( NULL == (item->data_bytes = (uint8_t*)rs_malloc(item->data_size))) - { - delete item; - return NULL ; - } - - memcpy(item->data_bytes,&((uint8_t*)data)[offset],item->data_size) ; - offset += item->data_size ; - } - else - item->data_bytes = NULL ; - - ok &= item->signature.GetTlv(data, pktsize, &offset) ; - - ok &= getRawUInt32(data, pktsize, &offset, &item->duplication_factor); - - // make sure the duplication factor is not altered by friends. In the worst case, the item will duplicate a bit more. - - if(item->duplication_factor < 1) - { - item->duplication_factor = 1 ; - std::cerr << "(II) correcting GRouter item duplication factor from 0 to 1, to ensure backward compat." << std::endl; - } - if(item->duplication_factor > GROUTER_MAX_DUPLICATION_FACTOR) - { - std::cerr << "(WW) correcting GRouter item duplication factor of " << item->duplication_factor << ". This is very unexpected." << std::endl; - item->duplication_factor = GROUTER_MAX_DUPLICATION_FACTOR ; - } - - ok &= getRawUInt32(data, pktsize, &offset, &item->flags); - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterSignedReceiptItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,routing_id,"routing_id") ; @@ -258,33 +118,6 @@ void RsGRouterSignedReceiptItem::serial_process(RsGenericSerializer::SerializeJo RsTypeSerializer::serial_process(j,ctx,signature,"signature") ; } -#ifdef TO_REMOVE -RsGRouterSignedReceiptItem *RsGRouterSerialiser::deserialise_RsGRouterSignedReceiptItem(void *data, uint32_t pktsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGRouterSignedReceiptItem *item = new RsGRouterSignedReceiptItem() ; - - ok &= getRawUInt64(data, pktsize, &offset, &item->routing_id); - ok &= getRawUInt32(data, pktsize, &offset, &item->flags); - ok &= item->destination_key.deserialise(data, pktsize, offset); - ok &= getRawUInt32(data, pktsize, &offset, &item->service_id); - ok &= item->data_hash.deserialise(data, pktsize, offset); - ok &= item->signature.GetTlv(data, pktsize, &offset); // signature - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterRoutingInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,peerId,"peerId") ; @@ -352,99 +185,11 @@ void RsGRouterRoutingInfoItem::serial_process(RsGenericSerializer::SerializeJob } } -#ifdef TO_REMOVE -RsGRouterRoutingInfoItem *RsGRouterSerialiser::deserialise_RsGRouterRoutingInfoItem(void *data, uint32_t pktsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGRouterRoutingInfoItem *item = new RsGRouterRoutingInfoItem() ; - - RsPeerId peer_id ; - ok &= peer_id.deserialise(data, pktsize, offset) ; - item->PeerId(peer_id) ; - - ok &= getRawUInt32(data, pktsize, &offset, &item->data_status); - ok &= getRawUInt32(data, pktsize, &offset, &item->tunnel_status); - ok &= getRawTimeT(data, pktsize, &offset, item->received_time_TS); - ok &= getRawTimeT(data, pktsize, &offset, item->last_sent_TS); - - ok &= getRawTimeT(data, pktsize, &offset, item->last_tunnel_request_TS); - ok &= getRawUInt32(data, pktsize, &offset, &item->sending_attempts); - - ok &= getRawUInt32(data, pktsize, &offset, &item->client_id); - ok &= item->item_hash.deserialise(data, pktsize, offset) ; - ok &= item->tunnel_hash.deserialise(data, pktsize, offset) ; - ok &= getRawUInt32(data, pktsize, &offset, &item->routing_flags) ; - - ok &= item->incoming_routes.GetTlv(data,pktsize,&offset) ; - - item->data_item = deserialise_RsGRouterGenericDataItem(&((uint8_t*)data)[offset],pktsize - offset) ; - if(item->data_item != NULL) - offset += item->data_item->serial_size() ; - else - ok = false ; - - // Receipt item is optional. - - if (offset < pktsize) - { // - item->receipt_item = deserialise_RsGRouterSignedReceiptItem(&((uint8_t*)data)[offset],pktsize - offset); - if (item->receipt_item != NULL) - offset += item->receipt_item->serial_size(); - else // - ok = false; - } - else // - item->receipt_item = NULL; - - - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterMatrixFriendListItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,reverse_friend_indices,"reverse_friend_indices") ; } -#ifdef TO_REMOVE -RsGRouterMatrixFriendListItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixFriendListItem(void *data, uint32_t pktsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGRouterMatrixFriendListItem *item = new RsGRouterMatrixFriendListItem() ; - - uint32_t nb_friends = 0 ; - ok &= getRawUInt32(data, pktsize, &offset, &nb_friends); // file hash - - item->reverse_friend_indices.resize(nb_friends) ; - - for(uint32_t i=0;ok && ireverse_friend_indices[i].deserialise(data, pktsize, offset) ; - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterMatrixTrackItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,provider_id,"provider_id") ; @@ -452,30 +197,6 @@ void RsGRouterMatrixTrackItem::serial_process(RsGenericSerializer::SerializeJob RsTypeSerializer::serial_process(j,ctx,time_stamp,"time_stamp") ; } -#ifdef TO_REMOVE -RsGRouterMatrixTrackItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixTrackItem(void *data, uint32_t pktsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGRouterMatrixTrackItem *item = new RsGRouterMatrixTrackItem() ; - - ok &= item->provider_id.deserialise(data, pktsize, offset) ; - ok &= item->message_id.deserialise(data,pktsize,offset) ; - ok &= getRawTimeT(data, pktsize, &offset, item->time_stamp) ; - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - void RsGRouterMatrixCluesItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,destination_key,"destination_key") ; @@ -489,44 +210,6 @@ template<> void RsTypeSerializer::serial_process(RsGenericSerializer::SerializeJ RsTypeSerializer::serial_process (j,ctx,s.time_stamp,name+":time_stamp") ; } -#ifdef TO_REMOVE -RsGRouterMatrixCluesItem *RsGRouterSerialiser::deserialise_RsGRouterMatrixCluesItem(void *data, uint32_t pktsize) const -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGRouterMatrixCluesItem *item = new RsGRouterMatrixCluesItem() ; - - ok &= item->destination_key.deserialise(data,pktsize,offset) ; - - uint32_t nb_clues = 0 ; - ok &= getRawUInt32(data, pktsize, &offset, &nb_clues); - - item->clues.clear() ; - - for(uint32_t j=0;jclues.push_back(HitE) ; - } - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -#endif - RsGRouterGenericDataItem *RsGRouterGenericDataItem::duplicate() const { RsGRouterGenericDataItem *item = new RsGRouterGenericDataItem ; @@ -565,508 +248,3 @@ RsGRouterSignedReceiptItem *RsGRouterSignedReceiptItem::duplicate() const return item ; } -#ifdef TO_REMOVE -uint32_t RsGRouterGenericDataItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += sizeof(GRouterMsgPropagationId) ; // routing id - s += destination_key.serial_size() ; // destination_key - s += 4 ; // data_size - s += 4 ; // service id - s += data_size ; // data - s += signature.TlvSize() ; // signature - s += 4 ; // duplication_factor - s += 4 ; // flags - - return s ; -} -uint32_t RsGRouterGenericDataItem::signed_data_size() const -{ - uint32_t s = 0 ; // no header - s += sizeof(GRouterMsgPropagationId) ; // routing id - s += destination_key.serial_size() ; // destination_key - s += 4 ; // data_size - s += 4 ; // service id - s += data_size ; // data - - return s ; -} -uint32_t RsGRouterSignedReceiptItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += sizeof(GRouterMsgPropagationId) ; // routing id - s += destination_key.serial_size() ; // destination_key - s += data_hash.serial_size() ; - s += 4 ; // state - s += 4 ; // service_id - s += signature.TlvSize() ; // signature - - return s ; -} -uint32_t RsGRouterSignedReceiptItem::signed_data_size() const -{ - uint32_t s = 0 ; // no header - s += sizeof(GRouterMsgPropagationId) ; // routing id - s += destination_key.serial_size() ; // destination_key - s += data_hash.serial_size() ; - s += 4 ; // service_id - s += 4 ; // state - - return s ; -} -uint32_t RsGRouterTransactionChunkItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += sizeof(GRouterMsgPropagationId) ; // routing id - s += 4 ; // chunk_start - s += 4 ; // chunk_size - s += 4 ; // total_size - s += chunk_size ; // data - - return s; -} -uint32_t RsGRouterTransactionAcknItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += sizeof(GRouterMsgPropagationId) ; // routing id - - return s; -} -bool RsGRouterTransactionChunkItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, propagation_id); - ok &= setRawUInt32(data, tlvsize, &offset, chunk_start); - ok &= setRawUInt32(data, tlvsize, &offset, chunk_size); - ok &= setRawUInt32(data, tlvsize, &offset, total_size); - - memcpy(&((uint8_t*)data)[offset],chunk_data,chunk_size) ; - offset += chunk_size ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool RsGRouterGenericDataItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, routing_id); - ok &= destination_key.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, service_id); - ok &= setRawUInt32(data, tlvsize, &offset, data_size); - - memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ; - offset += data_size ; - - ok &= signature.SetTlv(data, tlvsize, &offset) ; - - ok &= setRawUInt32(data, tlvsize, &offset, duplication_factor) ; - ok &= setRawUInt32(data, tlvsize, &offset, flags) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool RsGRouterTransactionAcknItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, propagation_id); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool RsGRouterGenericDataItem::serialise_signed_data(void *data,uint32_t size) const -{ - bool ok = true; - - uint32_t offset = 0; - uint32_t tlvsize = signed_data_size() ; - - if(tlvsize > size) - { - ok = false; - std::cerr << "RsGRouterReceiptItem::serialisedata() size error! Not enough size in supplied container." << std::endl; - } - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, routing_id); - ok &= destination_key.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, service_id); - ok &= setRawUInt32(data, tlvsize, &offset, data_size); - - memcpy(&((uint8_t*)data)[offset],data_bytes,data_size) ; - offset += data_size ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterGenericDataItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool RsGRouterSignedReceiptItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, routing_id); - ok &= setRawUInt32(data, tlvsize, &offset, flags); - ok &= destination_key.serialise(data,tlvsize,offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, service_id); - ok &= data_hash.serialise(data,tlvsize,offset) ; - ok &= signature.SetTlv(data,tlvsize,&offset) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterReceiptItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool RsGRouterSignedReceiptItem::serialise_signed_data(void *data,uint32_t size) const -{ - bool ok = true; - - uint32_t offset=0; - uint32_t tlvsize = signed_data_size() ; - - if(tlvsize > size) - { - ok = false; - std::cerr << "RsGRouterReceiptItem::serialisedata() size error! Not enough size in supplied container." << std::endl; - } - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, routing_id); - ok &= setRawUInt32(data, tlvsize, &offset, flags); - ok &= destination_key.serialise(data,tlvsize,offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, service_id); - ok &= data_hash.serialise(data,tlvsize,offset) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterReceiptItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -/* serialise the data to the buffer */ -uint32_t RsGRouterMatrixCluesItem::serial_size() const -{ - uint32_t s = 8 ; // header - - s += destination_key.serial_size() ; // Key size - s += 4 ; // list::size() - s += (4+4+8) * clues.size() ; - - return s ; -} -uint32_t RsGRouterMatrixFriendListItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += 4 ; // reverse_friend_indices.size() - s += RsPeerId::SIZE_IN_BYTES * reverse_friend_indices.size() ; // sha1 for published_key - - return s ; -} - -uint32_t RsGRouterMatrixTrackItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += 8 ; // time_stamp - s += RsPeerId::SIZE_IN_BYTES; // provider_id - s += RsMessageId::SIZE_IN_BYTES; // message_id - - return s ; -} - -uint32_t RsGRouterRoutingInfoItem::serial_size() const -{ - uint32_t s = 8 ; // header - s += PeerId().serial_size() ; - - s += 4 ; // data status_flags - s += 4 ; // tunnel status_flags - s += 8 ; // received_time - s += 8 ; // last_sent_TS - - s += 8 ; // last_TR_TS - s += 4 ; // sending attempts - - s += sizeof(GRouterServiceId) ; // service_id - s += tunnel_hash.serial_size() ; - s += item_hash.serial_size() ; - - s += 4 ; // routing_flags - s += incoming_routes.TlvSize() ; // incoming_routes - - s += data_item->serial_size(); // data_item - - if(receipt_item != NULL) - s += receipt_item->serial_size(); // receipt_item - - return s ; -} - -bool RsGRouterMatrixFriendListItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, reverse_friend_indices.size()); - - for(uint32_t i=0;ok && i::const_iterator it2(clues.begin());it2!=clues.end();++it2) - { - ok &= setRawUInt32(data, tlvsize, &offset, (*it2).friend_id) ; - ok &= setRawUFloat32(data, tlvsize, &offset, (*it2).weight) ; - ok &= setRawTimeT(data, tlvsize, &offset, (*it2).time_stamp) ; - } - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterMatrixCluesItem::serialisedata() size error! " << std::endl; - } - - return ok; -} - -bool RsGRouterMatrixTrackItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= provider_id.serialise(data, tlvsize, offset) ; - ok &= message_id.serialise(data,tlvsize,offset) ; - ok &= setRawTimeT(data, tlvsize, &offset, time_stamp) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterMatrixTrackItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool FriendTrialRecord::deserialise(void *data,uint32_t& offset,uint32_t size) -{ - bool ok = true ; - ok &= friend_id.deserialise(data, size, offset) ; - ok &= getRawTimeT(data, size, &offset, time_stamp) ; - ok &= getRawUFloat32(data, size, &offset, probability) ; - ok &= getRawUInt32(data, size, &offset, &nb_friends) ; - return ok ; -} -bool FriendTrialRecord::serialise(void *data,uint32_t& offset,uint32_t size) const -{ - bool ok = true ; - ok &= friend_id.serialise(data, size, offset) ; - ok &= setRawTimeT(data, size, &offset, time_stamp) ; - ok &= setRawUFloat32(data, size, &offset, probability) ; - ok &= setRawUInt32(data, size, &offset, nb_friends) ; - return ok ; -} -bool RsGRouterRoutingInfoItem::serialise(void *data,uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= PeerId().serialise(data, tlvsize, offset) ; // we keep this. - ok &= setRawUInt32(data, tlvsize, &offset, data_status) ; - ok &= setRawUInt32(data, tlvsize, &offset, tunnel_status) ; - ok &= setRawTimeT(data, tlvsize, &offset, received_time_TS) ; - ok &= setRawTimeT(data, tlvsize, &offset, last_sent_TS) ; - ok &= setRawTimeT(data, tlvsize, &offset, last_tunnel_request_TS) ; - ok &= setRawUInt32(data, tlvsize, &offset, sending_attempts) ; - - ok &= setRawUInt32(data, tlvsize, &offset, client_id) ; - ok &= item_hash.serialise(data, tlvsize, offset) ; - ok &= tunnel_hash.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, routing_flags) ; - - ok &= incoming_routes.SetTlv(data,tlvsize,&offset) ; - - uint32_t ns = size - offset ; - ok &= data_item->serialise( &((uint8_t*)data)[offset], ns) ; - offset += data_item->serial_size() ; - - if(receipt_item != NULL) - { - uint32_t ns = size - offset ; - ok &= receipt_item->serialise( &((uint8_t*)data)[offset], ns) ; - offset += receipt_item->serial_size() ; - } - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGRouterRoutingInfoItem::serialisedata() size error! " << std::endl; - } - - return ok; -} - -// -----------------------------------------------------------------------------------// -// ------------------------------------- IO --------------------------------------- // -// -----------------------------------------------------------------------------------// -// - -std::ostream& RsGRouterSignedReceiptItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterReceiptItem:" << std::endl ; - o << " direct origin: \""<< PeerId() << "\"" << std::endl ; - o << " Mid: " << std::hex << routing_id << std::dec << std::endl ; - o << " State: " << flags << std::endl ; - o << " Dest: " << destination_key << std::endl ; - o << " Sign: " << signature.keyId << std::endl ; - - return o ; -} -std::ostream& RsGRouterGenericDataItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterGenericDataItem:" << std::endl ; - o << " Direct origin: \""<< PeerId() << "\"" << std::endl ; - o << " Routing ID: " << std::hex << routing_id << std::dec << "\"" << std::endl ; - o << " Key: " << destination_key.toStdString() << std::endl ; - o << " Data size: " << data_size << std::endl ; - o << " Data hash: " << RsDirUtil::sha1sum(data_bytes,data_size) << std::endl ; - o << " signature key: " << signature.keyId << std::endl; - o << " duplication fac:" << duplication_factor << std::endl; - o << " flags: " << flags << std::endl; - - return o ; -} - -std::ostream& RsGRouterRoutingInfoItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterRoutingInfoItem:" << std::endl ; - o << " direct origin: "<< PeerId() << std::endl ; - o << " data status: "<< std::hex<< data_status << std::dec << std::endl ; - o << " tunnel status: "<< tunnel_status << std::endl ; - o << " recv time: "<< received_time_TS << std::endl ; - o << " Last sent: "<< last_sent_TS << std::endl ; - o << " Sending attempts:"<< sending_attempts << std::endl ; - o << " destination key: "<< data_item->destination_key << std::endl ; - o << " Client id: "<< client_id << std::endl ; - o << " item hash: "<< item_hash << std::endl ; - o << " tunnel hash: "<< tunnel_hash << std::endl ; - o << " Data size: "<< data_item->data_size << std::endl ; - o << " Signed receipt: "<< (void*)receipt_item << std::endl ; - - return o ; -} - -std::ostream& RsGRouterMatrixTrackItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterMatrixTrackItem:" << std::endl ; - o << " provider_id: " << provider_id << std::endl; - o << " message_id: " << message_id << std::endl; - o << " time_stamp: " << time_stamp << std::endl; - - return o ; -} -std::ostream& RsGRouterMatrixCluesItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterMatrixCluesItem:" << std::endl ; - o << " destination k: " << destination_key.toStdString() << std::endl; - o << " routing clues: " << clues.size() << std::endl; - - for(std::list::const_iterator it(clues.begin());it!=clues.end();++it) - o << " " << (*it).friend_id << " " << (*it).time_stamp << " " << (*it).weight << std::endl; - - return o ; -} -std::ostream& RsGRouterTransactionChunkItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterTransactionChunkItem:" << std::endl ; - o << " total_size: " << total_size << std::endl; - o << " chunk_size: " << chunk_size << std::endl; - o << " chunk_start: " << chunk_start << std::endl; - - return o ; -} -std::ostream& RsGRouterTransactionAcknItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterTransactionAcknItem:" << std::endl ; - o << " routing id: " << propagation_id << std::endl; - - return o ; -} -std::ostream& RsGRouterMatrixFriendListItem::print(std::ostream& o, uint16_t) -{ - o << "RsGRouterMatrixCluesItem:" << std::endl ; - o << " friends: " << reverse_friend_indices.size() << std::endl; - - return o ; -} -#endif diff --git a/libretroshare/src/grouter/p3grouter.cc b/libretroshare/src/grouter/p3grouter.cc index 998f7e636..d77903df8 100644 --- a/libretroshare/src/grouter/p3grouter.cc +++ b/libretroshare/src/grouter/p3grouter.cc @@ -2205,26 +2205,6 @@ Sha1CheckSum p3GRouter::makeTunnelHash(const RsGxsId& destination,const GRouterS return RsDirUtil::sha1sum(bytes,20) ; } -#ifdef TO_REMOVE -bool p3GRouter::locked_getGxsOwnIdAndClientIdFromHash(const TurtleFileHash& sum,RsGxsId& gxs_id,GRouterServiceId& client_id) -{ - assert( gxs_id.SIZE_IN_BYTES == 16) ; - assert(Sha1CheckSum::SIZE_IN_BYTES == 20) ; - - //gxs_id = RsGxsId(sum.toByteArray());// takes the first 16 bytes - //client_id = sum.toByteArray()[19] + (sum.toByteArray()[18] << 8) ; - - std::map::const_iterator it = _owned_key_ids.find(sum); - - if(it == _owned_key_ids.end()) - return false ; - - gxs_id = it->second.authentication_key ; - client_id = it->second.service_id ; - - return true ; -} -#endif bool p3GRouter::loadList(std::list& items) { { diff --git a/libretroshare/src/gxstunnel/rsgxstunnelitems.cc b/libretroshare/src/gxstunnel/rsgxstunnelitems.cc index bb56e93cc..8e488c190 100644 --- a/libretroshare/src/gxstunnel/rsgxstunnelitems.cc +++ b/libretroshare/src/gxstunnel/rsgxstunnelitems.cc @@ -52,152 +52,11 @@ RsItem *RsGxsTunnelSerialiser::create_item(uint16_t service,uint8_t item_subtype } } -#ifdef TO_REMOVE -std::ostream& RsGxsTunnelDHPublicKeyItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsTunnelDHPublicKeyItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << " Signature Key ID: " << signature.keyId << std::endl ; - out << " Public Key ID: " << gxs_key.keyId << std::endl ; - - printRsItemEnd(out, "RsGxsTunnelMsgItem", indent); - return out; -} - -std::ostream& RsGxsTunnelDataItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsTunnelDataItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << " message id : " << std::hex << unique_item_counter << std::dec << std::endl ; - out << " service id : " << std::hex << service_id << std::dec << std::endl ; - out << " flags : " << std::hex << flags << std::dec << std::endl ; - out << " size : " << data_size << std::endl ; - out << " data : " << RsUtil::BinToHex(data,std::min(50u,data_size)) << ((data_size>50u)?"...":"") << std::endl ; - - printRsItemEnd(out, "RsGxsTunnelDataItem", indent); - return out; -} -std::ostream& RsGxsTunnelDataAckItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsTunnelDataItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << " message id : " << std::hex << unique_item_counter << std::dec << std::endl ; - - printRsItemEnd(out, "RsGxsTunnelDataAckItem", indent); - return out; -} -std::ostream& RsGxsTunnelStatusItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsTunnelDataItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << " flags : " << std::hex << status << std::dec << std::endl ; - - printRsItemEnd(out, "RsGxsTunnelStatusItem", indent); - return out; -} - -/*************************************************************************/ -#endif - RsGxsTunnelDHPublicKeyItem::~RsGxsTunnelDHPublicKeyItem() { BN_free(public_key) ; } -#ifdef TO_REMOVE -/*************************************************************************/ - -RsItem *RsGxsTunnelSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - -#ifdef GXS_TUNNEL_ITEM_DEBUG - std::cerr << "deserializing packet..."<< std::endl ; -#endif - // look what we have... - if (*pktsize < rssize) /* check size */ - { - std::cerr << "GxsTunnel deserialisation: not enough size: pktsize=" << *pktsize << ", rssize=" << rssize << std::endl ; - return NULL; /* not enough data */ - } - - /* set the packet length */ - *pktsize = rssize; - - /* ready to load */ - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_GXS_TUNNEL != getRsItemService(rstype))) - { -#ifdef GXS_TUNNEL_ITEM_DEBUG - std::cerr << "GxsTunnel deserialisation: wrong type !" << std::endl ; -#endif - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_GXS_TUNNEL_DH_PUBLIC_KEY: return deserialise_RsGxsTunnelDHPublicKeyItem(data,*pktsize) ; - case RS_PKT_SUBTYPE_GXS_TUNNEL_DATA: return deserialise_RsGxsTunnelDataItem (data,*pktsize) ; - case RS_PKT_SUBTYPE_GXS_TUNNEL_DATA_ACK: return deserialise_RsGxsTunnelDataAckItem (data,*pktsize) ; - case RS_PKT_SUBTYPE_GXS_TUNNEL_STATUS: return deserialise_RsGxsTunnelStatusItem (data,*pktsize) ; - default: - std::cerr << "Unknown packet type in chat!" << std::endl ; - return NULL ; - } -} - -/*************************************************************************/ - -uint32_t RsGxsTunnelDHPublicKeyItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 4 ; // BN size - s += BN_num_bytes(public_key) ; // public_key - s += signature.TlvSize() ; // signature - s += gxs_key.TlvSize() ; // gxs_key - - return s ; -} - -uint32_t RsGxsTunnelDataItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 8 ; // counter - s += 4 ; // flags - s += 4 ; // service id - s += 4 ; // data_size - s += data_size; // data - - return s ; -} - -uint32_t RsGxsTunnelDataAckItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 8 ; // counter - - return s ; -} - -uint32_t RsGxsTunnelStatusItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 4 ; // flags - - return s ; -} -/*************************************************************************/ -#endif - void RsGxsTunnelDHPublicKeyItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,public_key,"public_key") ; @@ -243,88 +102,11 @@ template<> void RsTypeSerializer::print_data(const std::string& name,BIGNUM std::cerr << "[BIGNUM] : " << name << std::endl; } -#ifdef TO_REMOVE -bool RsGxsTunnelDHPublicKeyItem::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); - - /* skip the header */ - offset += 8; - - uint32_t s = BN_num_bytes(public_key) ; - - ok &= setRawUInt32(data, tlvsize, &offset, s); - - BN_bn2bin(public_key,&((unsigned char *)data)[offset]) ; - offset += s ; - - ok &= signature.SetTlv(data, tlvsize, &offset); - ok &= gxs_key.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsTunnelDHPublicKeyItem::serialiseItem() Size Error! offset=" << offset << ", tlvsize=" << tlvsize << std::endl; - } - return ok ; -} -#endif - void RsGxsTunnelStatusItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,status,"status") ; } -#ifdef TO_REMOVE -bool RsGxsTunnelStatusItem::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 GXS_TUNNEL_ITEM_DEBUG - std::cerr << "RsGxsTunnelSerialiser serialising chat status item." << std::endl; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, status); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size Error! " << std::endl; - } -#ifdef GXS_TUNNEL_ITEM_DEBUG - std::cerr << "computed size: " << 256*((unsigned char*)data)[6]+((unsigned char*)data)[7] << std::endl ; -#endif - - return ok; -} -#endif - void RsGxsTunnelDataItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,unique_item_counter,"unique_item_counter") ; @@ -339,247 +121,6 @@ void RsGxsTunnelDataAckItem::serial_process(RsGenericSerializer::SerializeJob j, RsTypeSerializer::serial_process(j,ctx,unique_item_counter,"unique_item_counter") ; } -#ifdef TO_REMOVE -bool RsGxsTunnelDataItem::serialise(void *dt, 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(dt, tlvsize, PacketId(), tlvsize); - -#ifdef GXS_TUNNEL_ITEM_DEBUG - std::cerr << "RsGxsTunnelSerialiser serialising chat status item." << std::endl; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt64(dt, tlvsize, &offset, unique_item_counter); - ok &= setRawUInt32(dt, tlvsize, &offset, flags); - ok &= setRawUInt32(dt, tlvsize, &offset, service_id); - ok &= setRawUInt32(dt, tlvsize, &offset, data_size); - - if(offset + data_size <= tlvsize) - { - memcpy(&((uint8_t*)dt)[offset],data,data_size) ; - offset += data_size ; - } - else - ok = false ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size Error! " << std::endl; - } - - return ok; -} -bool RsGxsTunnelDataAckItem::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 GXS_TUNNEL_ITEM_DEBUG - std::cerr << "RsGxsTunnelSerialiser serialising chat status item." << std::endl; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt64(data, tlvsize, &offset, unique_item_counter); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsTunnelSerialiser::serialiseItem() Size Error! " << std::endl; - } - - return ok; -} - -/*************************************************************************/ - -RsGxsTunnelDHPublicKeyItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDHPublicKeyItem(void *data,uint32_t /*size*/) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsTunnelDHPublicKeyItem *item = new RsGxsTunnelDHPublicKeyItem() ; - - uint32_t s=0 ; - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &s); - - if(s > rssize || rssize - s < offset) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - - item->public_key = BN_bin2bn(&((unsigned char *)data)[offset],s,NULL) ; - offset += s ; - - ok &= item->signature.GetTlv(data, rssize, &offset) ; - ok &= item->gxs_key.GetTlv(data, rssize, &offset) ; - - if (offset != rssize) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - if (!ok) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - - return item ; -} - -RsGxsTunnelDataItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDataItem(void *dat,uint32_t size) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(dat); - bool ok = true ; - - if(rssize > size) - { - std::cerr << "RsGxsTunnelDataItem::() Size error while deserializing." << std::endl ; - return NULL ; - } - - RsGxsTunnelDataItem *item = new RsGxsTunnelDataItem(); - - /* get mandatory parts first */ - - ok &= getRawUInt64(dat, rssize, &offset, &item->unique_item_counter); - ok &= getRawUInt32(dat, rssize, &offset, &item->flags); - ok &= getRawUInt32(dat, rssize, &offset, &item->service_id); - ok &= getRawUInt32(dat, rssize, &offset, &item->data_size); - - if(item->data_size > rssize || rssize < offset + item->data_size) - { - std::cerr << "RsGxsTunnelDataItem::() Size error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - item->data = (unsigned char*)rs_malloc(item->data_size) ; - - if(item->data == NULL) - { - delete item ; - return NULL ; - } - - memcpy(item->data,&((uint8_t*)dat)[offset],item->data_size) ; - offset += item->data_size ; - - - if (offset != rssize) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - if (!ok) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - - return item ; -} - -RsGxsTunnelDataAckItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelDataAckItem(void *dat,uint32_t /* size */) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(dat); - bool ok = true ; - - RsGxsTunnelDataAckItem *item = new RsGxsTunnelDataAckItem(); - - /* get mandatory parts first */ - - ok &= getRawUInt64(dat, rssize, &offset, &item->unique_item_counter); - - if (offset != rssize) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Size error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - if (!ok) - { - std::cerr << "RsGxsTunnelDHPublicKeyItem::() Unknown error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - - return item ; -} - -RsGxsTunnelStatusItem *RsGxsTunnelSerialiser::deserialise_RsGxsTunnelStatusItem(void *dat, uint32_t size) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(dat); - bool ok = true ; - - if(rssize > size) - { - std::cerr << "RsGxsTunnelStatusItem::() Size error while deserializing." << std::endl ; - return NULL ; - } - - RsGxsTunnelStatusItem *item = new RsGxsTunnelStatusItem(); - - /* get mandatory parts first */ - - ok &= getRawUInt32(dat, rssize, &offset, &item->status); - - if (offset != rssize) - { - std::cerr << "RsGxsTunnelStatusItem::() Size error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - if (!ok) - { - std::cerr << "RsGxsTunnelStatusItem::() Unknown error while deserializing." << std::endl ; - delete item ; - return NULL ; - } - - return item ; -} -#endif diff --git a/libretroshare/src/pqi/p3peermgr.cc b/libretroshare/src/pqi/p3peermgr.cc index 5ae948d86..cad91f30b 100644 --- a/libretroshare/src/pqi/p3peermgr.cc +++ b/libretroshare/src/pqi/p3peermgr.cc @@ -2294,44 +2294,6 @@ bool p3PeerMgrIMPL::loadList(std::list& load) continue; } -#ifdef TO_REMOVE - RsPeerGroupItem_deprecated *gitem = dynamic_cast(*it) ; - - if (gitem) - { - RsStackMutex stack(mPeerMtx); /****** STACK LOCK MUTEX *******/ - -#ifdef PEER_DEBUG - std::cerr << "p3PeerMgrIMPL::loadList() Peer group item:" << std::endl; - gitem->print(std::cerr, 10); - std::cerr << std::endl; -#endif - RsGroupInfo ginfo ; - ginfo.flag = gitem->flag ; - ginfo.name = gitem->name ; - ginfo.peerIds = gitem->pgpList.ids ; - - do { ginfo.id = RsNodeGroupId::random(); } while(groupList.find(ginfo.id) != groupList.end()) ; - - // Ensure backward compatibility when loading the group in old format. The id must matchthe standard default id. - - if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FRIENDS )) ginfo.id = RS_GROUP_ID_FRIENDS ; - if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_COWORKERS)) ginfo.id = RS_GROUP_ID_COWORKERS ; - if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAMILY )) ginfo.id = RS_GROUP_ID_FAMILY ; - if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAVORITES)) ginfo.id = RS_GROUP_ID_FAVORITES ; - if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_OTHERS )) ginfo.id = RS_GROUP_ID_OTHERS ; - - if(!ginfo.id.isNull()) - { - groupList[ginfo.id] = ginfo ; - std::cerr << "(II) Creating new group for old format local group \"" << gitem->name << "\". Id=" << ginfo.id << std::endl; - } - else - std::cerr << "(EE) no group corresponding to old format group with ID=\"" << gitem->id << "\"" << std::endl; - - continue; - } -#endif RsNodeGroupItem *gitem2 = dynamic_cast(*it) ; diff --git a/libretroshare/src/rsitems/rsbwctrlitems.cc b/libretroshare/src/rsitems/rsbwctrlitems.cc index 45c23d2c8..bfa172b45 100644 --- a/libretroshare/src/rsitems/rsbwctrlitems.cc +++ b/libretroshare/src/rsitems/rsbwctrlitems.cc @@ -57,143 +57,5 @@ void RsBwCtrlAllowedItem::serial_process(RsGenericSerializer::SerializeJob j,RsG RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_UINT32_BW,allowedBw,"allowedBw") ; } -#ifdef TO_REMOVE -/* serialise the data to the buffer */ -bool RsBwCtrlSerialiser::serialiseAllowed(RsBwCtrlAllowedItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeAllowed(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Header: " << ok << std::endl; - std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= SetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, item->allowedBw); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsBwCtrlSerialiser::serialiseRoute() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsBwCtrlAllowedItem *RsBwCtrlSerialiser::deserialiseAllowed(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t tlvsize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_BWCTRL != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < tlvsize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = tlvsize; - - bool ok = true; - - /* ready to load */ - RsBwCtrlAllowedItem *item = new RsBwCtrlAllowedItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= GetTlvUInt32(data, tlvsize, &offset, TLV_TYPE_UINT32_BW, &(item->allowedBw)); - - - if (offset != tlvsize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ - -uint32_t RsBwCtrlSerialiser::size(RsItem *i) -{ - RsBwCtrlAllowedItem *dri; - - if (NULL != (dri = dynamic_cast(i))) - { - return sizeAllowed(dri); - } - return 0; -} - -bool RsBwCtrlSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsBwCtrlAllowedItem *dri; - - if (NULL != (dri = dynamic_cast(i))) - { - return serialiseAllowed(dri, data, pktsize); - } - return false; -} - -RsItem *RsBwCtrlSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_BWCTRL != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_BWCTRL_ALLOWED_ITEM: - return deserialiseAllowed(data, pktsize); - break; - default: - return NULL; - break; - } -} - -/*************************************************************************/ -#endif - diff --git a/libretroshare/src/rsitems/rsconfigitems.h b/libretroshare/src/rsitems/rsconfigitems.h index d4ea41898..4e31b2d43 100644 --- a/libretroshare/src/rsitems/rsconfigitems.h +++ b/libretroshare/src/rsitems/rsconfigitems.h @@ -140,30 +140,6 @@ class RsPeerBandwidthLimitsItem : public RsItem std::map peers ; }; -#ifdef TO_REMOVE -class RsPeerGroupItem_deprecated : public RsItem -{ -public: - RsPeerGroupItem_deprecated(); - virtual ~RsPeerGroupItem_deprecated(); - - virtual void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); - - /* set data from RsGroupInfo to RsPeerGroupItem */ - void set(RsGroupInfo &groupInfo); - /* get data from RsGroupInfo to RsPeerGroupItem */ - void get(RsGroupInfo &groupInfo); - - /* Mandatory */ - std::string id; - std::string name; - uint32_t flag; - - RsTlvPgpIdSet pgpList; -}; -#endif - class RsNodeGroupItem: public RsItem { public: @@ -216,51 +192,6 @@ class RsPeerConfigSerialiser: public RsConfigSerializer /**************************************************************************/ -#ifdef TO_REMOVE -class RsCacheConfig: public RsItem -{ - public: - RsCacheConfig() - :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, - RS_PKT_TYPE_CACHE_CONFIG, - RS_PKT_SUBTYPE_DEFAULT) - { return; } -virtual ~RsCacheConfig(); -virtual void clear(); -std::ostream &print(std::ostream &out, uint16_t indent = 0); - - RsPeerId pid; /* Mandatory */ - uint16_t cachetypeid; /* Mandatory */ - uint16_t cachesubid; /* Mandatory */ - - std::string path; /* Mandatory */ - std::string name; /* Mandatory */ - RsFileHash hash; /* Mandatory */ - uint64_t size; /* Mandatory */ - - uint32_t recvd; /* Mandatory */ -}; - - -class RsCacheConfigSerialiser: public RsSerialType -{ - public: - RsCacheConfigSerialiser() - :RsSerialType(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, - RS_PKT_TYPE_CACHE_CONFIG) - { return; } - -virtual ~RsCacheConfigSerialiser(); - -virtual uint32_t size(RsItem *); -virtual bool serialise (RsItem *item, void *data, uint32_t *size); -virtual RsItem * deserialise(void *data, uint32_t *size); - -}; -#endif - -/**************************************************************************/ - class RsFileTransfer: public RsItem { public: @@ -306,26 +237,6 @@ class RsFileTransfer: public RsItem const uint32_t RS_FILE_CONFIG_CLEANUP_DELETE = 0x0001; -#ifdef TO_REMOVE -/* Used by ft / extralist / configdirs / anyone who wants a basic file */ -class RsFileConfigItem_deprecated: public RsItem -{ -public: - RsFileConfigItem_deprecated() - :RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONFIG, - RS_PKT_TYPE_FILE_CONFIG, - RS_PKT_SUBTYPE_FILE_ITEM_deprecated) - {} - virtual ~RsFileConfigItem_deprecated() {} - virtual void clear(); - std::ostream &print(std::ostream &out, uint16_t indent = 0); - - RsTlvFileItem file; - uint32_t flags; - std::list parent_groups ; -}; -#endif - class RsFileConfigItem: public RsItem { public: diff --git a/libretroshare/src/rsitems/rsgxscommentitems.cc b/libretroshare/src/rsitems/rsgxscommentitems.cc index 407f64204..8c175a1bd 100644 --- a/libretroshare/src/rsitems/rsgxscommentitems.cc +++ b/libretroshare/src/rsitems/rsgxscommentitems.cc @@ -46,403 +46,14 @@ RsItem *RsGxsCommentSerialiser::create_item(uint16_t service_id,uint8_t item_sub } } -#ifdef TO_REMOVE - -uint32_t RsGxsCommentSerialiser::size(RsItem *item) -{ -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::size()" << std::endl; -#endif - - RsGxsCommentItem* com_item = NULL; - RsGxsVoteItem* vote_item = NULL; - - if((com_item = dynamic_cast(item)) != NULL) - { - return sizeGxsCommentItem(com_item); - } - else if((vote_item = dynamic_cast(item)) != NULL) - { - return sizeGxsVoteItem(vote_item); - } - std::cerr << "RsGxsCommentSerialiser::size() ERROR invalid item" << std::endl; - return 0; -} - -bool RsGxsCommentSerialiser::serialise(RsItem *item, void *data, uint32_t *size) -{ -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialise()" << std::endl; -#endif - - RsGxsCommentItem* com_item = NULL; - RsGxsVoteItem* vote_item = NULL; - - if((com_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsCommentItem(com_item, data, size); - } - else if((vote_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsVoteItem(vote_item, data, size); - } - std::cerr << "RsGxsCommentSerialiser::serialise() ERROR invalid item" << std::endl; - return false; -} - -RsItem* RsGxsCommentSerialiser::deserialise(void* data, uint32_t* size) -{ - -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (getRsItemService(PacketId()) != getRsItemService(rstype))) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialise() ERROR Wrong Type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - - case RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM: - return deserialiseGxsCommentItem(data, size); - break; - case RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM: - return deserialiseGxsVoteItem(data, size); - break; - default: -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialise(): unknown subtype"; - std::cerr << std::endl; -#endif - break; - } - return NULL; -} - - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - -void RsGxsCommentItem::clear() -{ - mMsg.mComment.clear(); -} - -std::ostream& RsGxsCommentItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsCommentItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Comment: " << mMsg.mComment << std::endl; - - printRsItemEnd(out ,"RsGxsCommentItem", indent); - return out; -} - - -uint32_t RsGxsCommentSerialiser::sizeGxsCommentItem(RsGxsCommentItem *item) -{ - - const RsGxsComment& msg = item->mMsg; - uint32_t s = 8; // header - - s += GetTlvStringSize(msg.mComment); // mMsg. - -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::sizeGxsCommentItem() is: " << s << std::endl; - msg.print(std::cerr); -#endif - - return s; -} -#endif - void RsGxsCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,1,mMsg.mComment,"mMsg.mComment") ; } -#ifdef TO_REMOVE -bool RsGxsCommentSerialiser::serialiseGxsCommentItem(RsGxsCommentItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsCommentItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem() Failed size too small" << std::endl; -#endif - - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsCommentItem */ - ok &= SetTlvString(data, tlvsize, &offset, 1, item->mMsg.mComment); - - if(offset != tlvsize) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSCOMMENT_DEBUG - if (!ok) - { - std::cerr << "RsGxsCommentSerialiser::serialiseGxsCommentItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsCommentItem* RsGxsCommentSerialiser::deserialiseGxsCommentItem(void *data, uint32_t *size) -{ - -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (getRsItemService(PacketId()) != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSCOMMENT_COMMENT_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsCommentItem* item = new RsGxsCommentItem(getRsItemService(PacketId())); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, 1, item->mMsg.mComment); - - if (offset != rssize) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsCommentItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - -void RsGxsVoteItem::clear() -{ - mMsg.mVoteType = 0; -} - -std::ostream& RsGxsVoteItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsVoteItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "VoteType: " << mMsg.mVoteType << std::endl; - - printRsItemEnd(out ,"RsGxsVoteItem", indent); - return out; -} - - -uint32_t RsGxsCommentSerialiser::sizeGxsVoteItem(RsGxsVoteItem */*item*/) -{ - uint32_t s = 8; // header - - s += 4; // vote flags. - - return s; -} -#endif - void RsGxsVoteItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mMsg.mVoteType,"mMsg.mVoteType") ; } -#ifdef TO_REMOVE -bool RsGxsCommentSerialiser::serialiseGxsVoteItem(RsGxsVoteItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsVoteItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsVoteItem */ - ok &= setRawUInt32(data, tlvsize, &offset, item->mMsg.mVoteType); - - if(offset != tlvsize) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSCOMMENT_DEBUG - if (!ok) - { - std::cerr << "RsGxsCommentSerialiser::serialiseGxsVoteItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsVoteItem* RsGxsCommentSerialiser::deserialiseGxsVoteItem(void *data, uint32_t *size) -{ - -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (getRsItemService(PacketId()) != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSCOMMENT_VOTE_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsVoteItem* item = new RsGxsVoteItem(getRsItemService(PacketId())); - /* skip the header */ - offset += 8; - - ok &= getRawUInt32(data, rssize, &offset, &(item->mMsg.mVoteType)); - - if (offset != rssize) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSCOMMENT_DEBUG - std::cerr << "RsGxsCommentSerialiser::deserialiseGxsVoteItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#endif diff --git a/libretroshare/src/rsitems/rsgxsiditems.cc b/libretroshare/src/rsitems/rsgxsiditems.cc index 5bf55b549..1a4eac4e8 100644 --- a/libretroshare/src/rsitems/rsgxsiditems.cc +++ b/libretroshare/src/rsitems/rsgxsiditems.cc @@ -60,172 +60,12 @@ void RsGxsIdGroupItem::clear() mRecognTags.clear(); mImage.TlvClear(); } -#ifdef TO_REMOVE -RsItem* RsGxsIdSerialiser::deserialise(void* data, uint32_t* size) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype))) - return NULL; /* wrong type */ - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_GXSID_GROUP_ITEM: return deserialise_GxsIdGroupItem(data, size); - case RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM: return deserialise_GxsIdLocalInfoItem(data, size); -#if 0 - case RS_PKT_SUBTYPE_GXSID_OPINION_ITEM: return deserialise_GxsIdOpinionItem(data, size); - case RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM: return deserialise_GxsIdCommentItem(data, size); -#endif - default: -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialise(): unknown subtype"; - std::cerr << std::endl; -#endif - break; - } - return NULL; -} - -bool RsGxsIdItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) -{ - tlvsize = serial_size() ; - offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize)) - { - std::cerr << "RsItem::serialise_header(): ERROR. Not enough size!" << std::endl; - return false ; - } - offset += 8; - - return true ; -} - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - - - -uint32_t RsGxsIdLocalInfoItem::serial_size() -{ - uint32_t s = 8 ; // header - s += 4 ; // number of items - s += mTimeStamps.size() * (RsGxsId::SIZE_IN_BYTES + 8) ; - s += 4 ; // number of contacts - s += mContacts.size() * RsGxsId::SIZE_IN_BYTES ; - - return s; -} - -std::ostream& RsGxsIdLocalInfoItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsIdLocalInfoItem", indent); - - // convert from binary to hex. - for(std::map::const_iterator it(mTimeStamps.begin());it!=mTimeStamps.end();++it) - out << it->first << " : " << it->second << std::endl; - - printRsItemEnd(out ,"RsGxsIdLocalInfoItem", indent); - return out; -} -std::ostream& RsGxsIdGroupItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsIdGroupItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "MetaData: " << meta << std::endl; - printIndent(out, int_Indent); - out << "PgpIdHash: " << mPgpIdHash << std::endl; - printIndent(out, int_Indent); - - std::string signhex; - // convert from binary to hex. - for(unsigned int i = 0; i < mPgpIdSign.length(); i++) - { - rs_sprintf_append(signhex, "%02x", (uint32_t) ((uint8_t) mPgpIdSign[i])); - } - out << "PgpIdSign: " << signhex << std::endl; - printIndent(out, int_Indent); - out << "RecognTags:" << std::endl; - - RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags); - set.print(out, int_Indent + 2); - - printRsItemEnd(out ,"RsGxsIdGroupItem", indent); - return out; -} - - -uint32_t RsGxsIdGroupItem::serial_size() -{ - uint32_t s = 8; // header - - s += Sha1CheckSum::SIZE_IN_BYTES; - s += GetTlvStringSize(mPgpIdSign); - - RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags); - s += set.TlvSize(); - s += mImage.TlvSize() ; - - return s; -} -#endif - void RsGxsIdLocalInfoItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mTimeStamps,"mTimeStamps") ; RsTypeSerializer::serial_process(j,ctx,mContacts,"mContacts") ; } -#ifdef TO_REMOVE -bool RsGxsIdLocalInfoItem::serialise(void *data, uint32_t& size) -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, tlvsize, &offset, mTimeStamps.size()) ; - - for(std::map::const_iterator it = mTimeStamps.begin();it!=mTimeStamps.end();++it) - { - ok &= it->first.serialise(data,tlvsize,offset) ; - ok &= setRawTimeT(data,tlvsize,&offset,it->second) ; - } - ok &= setRawUInt32(data, tlvsize, &offset, mContacts.size()) ; - - for(std::set::const_iterator it(mContacts.begin());it!=mContacts.end();++it) - ok &= (*it).serialise(data,tlvsize,offset) ; - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl; - } -#endif - - return ok; -} -#endif - void RsGxsIdGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,mPgpIdHash,"mPgpIdHash") ; @@ -243,43 +83,6 @@ void RsGxsIdGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGene RsTypeSerializer::serial_process(j,ctx,mImage,"mImage") ; } -#ifdef TO_REMOVE -bool RsGxsIdGroupItem::serialise(void *data, uint32_t& size) -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* GxsIdGroupItem */ - ok &= mPgpIdHash.serialise(data, tlvsize, offset); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_SIGN, mPgpIdSign); - - RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, mRecognTags); - ok &= set.SetTlv(data, tlvsize, &offset); - - ok &= mImage.SetTlv(data,tlvsize,&offset) ; - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdGroupItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl; - } -#endif - - return ok; -} -#endif - bool RsGxsIdGroupItem::fromGxsIdGroup(RsGxsIdGroup &group, bool moveImage) { clear(); @@ -320,422 +123,3 @@ bool RsGxsIdGroupItem::toGxsIdGroup(RsGxsIdGroup &group, bool moveImage) return true ; } -#ifdef TO_REMOVE -RsGxsIdGroupItem* RsGxsIdSerialiser::deserialise_GxsIdGroupItem(void *data, uint32_t *size) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSID_GROUP_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsIdGroupItem* item = new RsGxsIdGroupItem(); - /* skip the header */ - offset += 8; - - ok &= item->mPgpIdHash.deserialise(data, rssize, offset); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_SIGN, item->mPgpIdSign); - - RsTlvStringSetRef set(TLV_TYPE_RECOGNSET, item->mRecognTags); - ok &= set.GetTlv(data, rssize, &offset); - - // image is optional,so that we can continue reading old items. - if(offset < rssize) - ok &= item->mImage.GetTlv(data,rssize,&offset) ; - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} -RsGxsIdLocalInfoItem *RsGxsIdSerialiser::deserialise_GxsIdLocalInfoItem(void *data, uint32_t *size) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSID_LOCAL_INFO_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsIdLocalInfoItem* item = new RsGxsIdLocalInfoItem(); - /* skip the header */ - offset += 8; - - uint32_t n=0 ; - ok &= getRawUInt32(data, rssize, &offset, &n) ; - - for(uint32_t i=0;ok && imTimeStamps[gxsid] = TS ; - } - - if (offset < rssize) // backward compatibility, making that section optional. - { - ok &= getRawUInt32(data, rssize, &offset, &n) ; - RsGxsId gxsid ; - - for(uint32_t i=0;ok && imContacts.insert(gxsid) ; - } - } - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdGroupItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -#endif - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#if 0 - -void RsGxsIdOpinionItem::clear() -{ - opinion.mOpinion = 0; - opinion.mReputation = 0; - opinion.mComment = ""; -} - -std::ostream& RsGxsIdOpinionItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsIdOpinionItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Opinion: " << opinion.mOpinion << std::endl; - printIndent(out, int_Indent); - out << "Reputation: " << opinion.mReputation << std::endl; - printIndent(out, int_Indent); - out << "Comment: " << opinion.mComment << std::endl; - - printRsItemEnd(out ,"RsGxsIdOpinionItem", indent); - return out; -} - - -uint32_t RsGxsIdOpinionItem::serial_size() -{ - - const RsGxsIdOpinion& opinion = item->opinion; - uint32_t s = 8; // header - - s += 4; // mOpinion. - s += 4; // mReputation. - s += GetTlvStringSize(opinion.mComment); - - return s; -} - -bool RsGxsIdOpinionItem::serialise(void *data, uint32_t *size) -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* GxsIdOpinionItem */ - ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mOpinion); - ok &= setRawUInt32(data, tlvsize, &offset, item->opinion.mReputation); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->opinion.mComment); - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdOpinionItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsIdOpinionItem* RsGxsIdSerialiser::deserialise_GxsIdOpinionItem(void *data, uint32_t *size) -{ - - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSID_OPINION_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsIdOpinionItem* item = new RsGxsIdOpinionItem(); - /* skip the header */ - offset += 8; - - ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mOpinion)); - ok &= getRawUInt32(data, rssize, &offset, &(item->opinion.mReputation)); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->opinion.mComment); - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdOpinionItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - -void RsGxsIdCommentItem::clear() -{ - comment.mComment.clear(); -} - -std::ostream& RsGxsIdCommentItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsIdCommentItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Comment: " << comment.mComment << std::endl; - - printRsItemEnd(out ,"RsGxsIdCommentItem", indent); - return out; -} - - -uint32_t RsGxsIdCommentItem::serial_size() -{ - - const RsGxsIdComment& comment = item->comment; - uint32_t s = 8; // header - - s += GetTlvStringSize(comment.mComment); - - return s; -} - -bool RsGxsIdCommentItem::serialise(void *data, uint32_t *size) -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* GxsIdCommentItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment); - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdCommentItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsIdSerialiser::serialiseGxsIdgroupItem() NOK" << std::endl; - } -#endif - - return ok; -} - -RsGxsIdCommentItem* RsGxsIdSerialiser::deserialise_GxsIdCommentItem(void *data, uint32_t *size) -{ - - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_GXSID != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_GXSID_COMMENT_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsIdCommentItem* item = new RsGxsIdCommentItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment); - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsIdSerialiser::deserialiseGxsIdCommentItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -#endif diff --git a/libretroshare/src/rsitems/rsgxsrecognitems.cc b/libretroshare/src/rsitems/rsgxsrecognitems.cc index 81b8d866b..bb6a40ca8 100644 --- a/libretroshare/src/rsitems/rsgxsrecognitems.cc +++ b/libretroshare/src/rsitems/rsgxsrecognitems.cc @@ -63,65 +63,6 @@ void RsGxsRecognReqItem::clear() sign.TlvClear(); } -#ifdef TO_REMOVE -RsGxsRecognReqItem::~RsGxsRecognReqItem() -{ - return; -} - - -std::ostream &RsGxsRecognReqItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsRecognReqItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "issued_at: " << issued_at << std::endl; - - printIndent(out, int_Indent); - out << "period: " << period << std::endl; - - printIndent(out, int_Indent); - out << "tag_class: " << tag_class << std::endl; - - printIndent(out, int_Indent); - out << "tag_type: " << tag_type << std::endl; - - printIndent(out, int_Indent); - out << "identity: " << identity << std::endl; - - printIndent(out, int_Indent); - out << "nickname: " << nickname << std::endl; - - printIndent(out, int_Indent); - out << "comment: " << comment << std::endl; - - printIndent(out, int_Indent); - out << "signature: " << std::endl; - sign.print(out, int_Indent + 2); - - printRsItemEnd(out, "RsGxsRecognReqItem", indent); - return out; -} - - -uint32_t RsGxsRecognSerialiser::sizeReq(RsGxsRecognReqItem *item) -{ - uint32_t s = 8; /* header */ - s += 4; // issued_at; - s += 4; // period; - s += 2; // tag_class; - s += 2; // tag_type; - s += item->identity.serial_size(); - s += GetTlvStringSize(item->nickname); - s += GetTlvStringSize(item->comment); - s += item->sign.TlvSize(); - - return s; -} - -#endif - void RsGxsRecognReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,issued_at ,"issued_at") ; @@ -134,122 +75,6 @@ void RsGxsRecognReqItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe RsTypeSerializer::serial_process(j,ctx,sign ,"sign") ; } -#ifdef TO_REMOVE -/* serialise the data to the buffer */ -bool RsGxsRecognSerialiser::serialiseReq(RsGxsRecognReqItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeReq(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsRecognSerialiser::serialiseReq() Header: " << ok << std::endl; - std::cerr << "RsGxsRecognSerialiser::serialiseReq() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, item->issued_at); - ok &= setRawUInt32(data, tlvsize, &offset, item->period); - ok &= setRawUInt16(data, tlvsize, &offset, item->tag_class); - ok &= setRawUInt16(data, tlvsize, &offset, item->tag_type); - - - ok &= item->identity.serialise(data, tlvsize, offset); - ok &= SetTlvString(data, tlvsize, &offset, 1, item->nickname); - ok &= SetTlvString(data, tlvsize, &offset, 1, item->comment); - - ok &= item->sign.SetTlv(data, tlvsize, &offset); - - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsRecognSerialiser::serialiseReq() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsGxsRecognReqItem *RsGxsRecognSerialiser::deserialiseReq(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t tlvsize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_RECOGN_REQ != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < tlvsize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = tlvsize; - - bool ok = true; - - /* ready to load */ - RsGxsRecognReqItem *item = new RsGxsRecognReqItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= getRawUInt32(data, tlvsize, &offset, &(item->issued_at)); - ok &= getRawUInt32(data, tlvsize, &offset, &(item->period)); - ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_class)); - ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_type)); - - - ok &= item->identity.serialise(data, tlvsize, offset); - ok &= GetTlvString(data, tlvsize, &offset, 1, item->nickname); - ok &= GetTlvString(data, tlvsize, &offset, 1, item->comment); - ok &= item->sign.GetTlv(data, tlvsize, &offset); - - - if (offset != tlvsize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ - -RsGxsRecognTagItem::~RsGxsRecognTagItem() -{ - return; -} -#endif - void RsGxsRecognTagItem::clear() { valid_from = 0; @@ -264,56 +89,6 @@ void RsGxsRecognTagItem::clear() sign.TlvClear(); } -#ifdef TO_REMOVE -std::ostream &RsGxsRecognTagItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsRecognTagItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "valid_from: " << valid_from << std::endl; - - printIndent(out, int_Indent); - out << "valid_to: " << valid_to << std::endl; - - printIndent(out, int_Indent); - out << "tag_class: " << tag_class << std::endl; - - printIndent(out, int_Indent); - out << "tag_type: " << tag_type << std::endl; - - printIndent(out, int_Indent); - out << "identity: " << identity << std::endl; - - printIndent(out, int_Indent); - out << "nickname: " << nickname << std::endl; - - printIndent(out, int_Indent); - out << "signature: " << std::endl; - sign.print(out, int_Indent + 2); - - printRsItemEnd(out, "RsGxsRecognTagItem", indent); - return out; -} - - -uint32_t RsGxsRecognSerialiser::sizeTag(RsGxsRecognTagItem *item) -{ - uint32_t s = 8; /* header */ - s += 4; // valid_from; - s += 4; // valid_to; - s += 2; // tag_class; - s += 2; // tag_type; - - s += item->identity.serial_size(); - s += GetTlvStringSize(item->nickname); - - s += item->sign.TlvSize(); - - return s; -} -#endif - void RsGxsRecognTagItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process (j,ctx,valid_from ,"valid_from") ; @@ -325,122 +100,6 @@ void RsGxsRecognTagItem::serial_process(RsGenericSerializer::SerializeJob j,RsGe RsTypeSerializer::serial_process(j,ctx,sign ,"sign") ; } -#ifdef TO_REMOVE -/* serialise the data to the buffer */ -bool RsGxsRecognSerialiser::serialiseTag(RsGxsRecognTagItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeTag(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsRecognSerialiser::serialiseTag() Header: " << ok << std::endl; - std::cerr << "RsGxsRecognSerialiser::serialiseTag() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, item->valid_from); - ok &= setRawUInt32(data, tlvsize, &offset, item->valid_to); - - ok &= setRawUInt16(data, tlvsize, &offset, item->tag_class); - ok &= setRawUInt16(data, tlvsize, &offset, item->tag_type); - - - ok &= item->identity.serialise(data, tlvsize, offset); - ok &= SetTlvString(data, tlvsize, &offset, 1, item->nickname); - - ok &= item->sign.SetTlv(data, tlvsize, &offset); - - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsRecognSerialiser::serialiseTag() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsGxsRecognTagItem *RsGxsRecognSerialiser::deserialiseTag(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t tlvsize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_RECOGN_TAG != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < tlvsize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = tlvsize; - - bool ok = true; - - /* ready to load */ - RsGxsRecognTagItem *item = new RsGxsRecognTagItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= getRawUInt32(data, tlvsize, &offset, &(item->valid_from)); - ok &= getRawUInt32(data, tlvsize, &offset, &(item->valid_to)); - - ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_class)); - ok &= getRawUInt16(data, tlvsize, &offset, &(item->tag_type)); - - - ok &= item->identity.deserialise(data, tlvsize, offset); - ok &= GetTlvString(data, tlvsize, &offset, 1, item->nickname); - ok &= item->sign.GetTlv(data, tlvsize, &offset); - - - if (offset != tlvsize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ - -RsGxsRecognSignerItem::~RsGxsRecognSignerItem() -{ - return; -} -#endif - void RsGxsRecognSignerItem::clear() { signing_classes.TlvClear(); @@ -448,43 +107,6 @@ void RsGxsRecognSignerItem::clear() sign.TlvClear(); } -#ifdef TO_REMOVE -std::ostream &RsGxsRecognSignerItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsRecognSignerItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "signing_classes: " << std::endl; - signing_classes.print(out, int_Indent + 2); - - printIndent(out, int_Indent); - out << "key: " << std::endl; - key.print(out, int_Indent + 2); - - printIndent(out, int_Indent); - out << "signature: " << std::endl; - sign.print(out, int_Indent + 2); - - - printRsItemEnd(out, "RsGxsRecognSignerItem", indent); - return out; -} - - - - -uint32_t RsGxsRecognSerialiser::sizeSigner(RsGxsRecognSignerItem *item) -{ - uint32_t s = 8; /* header */ - s += item->signing_classes.TlvSize(); - s += item->key.TlvSize(); - s += item->sign.TlvSize(); - - return s; -} -#endif - void RsGxsRecognSignerItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,signing_classes ,"signing_classes") ; @@ -492,175 +114,5 @@ void RsGxsRecognSignerItem::serial_process(RsGenericSerializer::SerializeJob j,R RsTypeSerializer::serial_process(j,ctx,sign ,"sign") ; } -#ifdef TO_REMOVE -/* serialise the data to the buffer */ -bool RsGxsRecognSerialiser::serialiseSigner(RsGxsRecognSignerItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeSigner(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsRecognSerialiser::serialiseSigner() Header: " << ok << std::endl; - std::cerr << "RsGxsRecognSerialiser::serialiseSigner() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->signing_classes.SetTlv(data, tlvsize, &offset); - ok &= item->key.SetTlv(data, tlvsize, &offset); - ok &= item->sign.SetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsGxsRecognSerialiser::serialiseSigner() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsGxsRecognSignerItem *RsGxsRecognSerialiser::deserialiseSigner(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t tlvsize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_RECOGN_SIGNER != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < tlvsize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = tlvsize; - - bool ok = true; - - /* ready to load */ - RsGxsRecognSignerItem *item = new RsGxsRecognSignerItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= item->signing_classes.GetTlv(data, tlvsize, &offset); - ok &= item->key.GetTlv(data, tlvsize, &offset); - ok &= item->sign.GetTlv(data, tlvsize, &offset); - - if (offset != tlvsize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - - -/*************************************************************************/ - -uint32_t RsGxsRecognSerialiser::size(RsItem *i) -{ - RsGxsRecognReqItem *rqi; - RsGxsRecognTagItem *rti; - RsGxsRecognSignerItem *rsi; - - if (NULL != (rqi = dynamic_cast(i))) - { - return sizeReq(rqi); - } - if (NULL != (rti = dynamic_cast(i))) - { - return sizeTag(rti); - } - if (NULL != (rsi = dynamic_cast(i))) - { - return sizeSigner(rsi); - } - return 0; -} - -bool RsGxsRecognSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ - RsGxsRecognReqItem *rri; - RsGxsRecognTagItem *rti; - RsGxsRecognSignerItem *rsi; - - if (NULL != (rri = dynamic_cast(i))) - { - return serialiseReq(rri, data, pktsize); - } - if (NULL != (rti = dynamic_cast(i))) - { - return serialiseTag(rti, data, pktsize); - } - if (NULL != (rsi = dynamic_cast(i))) - { - return serialiseSigner(rsi, data, pktsize); - } - return false; -} - -RsItem *RsGxsRecognSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - if (*pktsize < getRsPktBaseSize()) - return NULL ; - - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_GXS_RECOGN != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_RECOGN_REQ: - return deserialiseReq(data, pktsize); - break; - case RS_PKT_SUBTYPE_RECOGN_TAG: - return deserialiseTag(data, pktsize); - break; - case RS_PKT_SUBTYPE_RECOGN_SIGNER: - return deserialiseSigner(data, pktsize); - break; - default: - return NULL; - break; - } -} - -/*************************************************************************/ -#endif diff --git a/libretroshare/src/rsitems/rsgxsreputationitems.cc b/libretroshare/src/rsitems/rsgxsreputationitems.cc index 2a559b052..7b558131a 100644 --- a/libretroshare/src/rsitems/rsgxsreputationitems.cc +++ b/libretroshare/src/rsitems/rsgxsreputationitems.cc @@ -88,525 +88,6 @@ void RsGxsReputationRequestItem::serial_process(RsGenericSerializer::SerializeJo RsTypeSerializer::serial_process(j,ctx,mLastUpdate,"mLastUpdate") ; } -#ifdef TO_REMOVE -// re-defined here, in order to avoid cross-includes -#define REPUTATION_IDENTITY_FLAG_NEEDS_UPDATE 0x0100 - -/*************************************************************************/ -/*************************************************************************/ -/*************************************************************************/ - -std::ostream& RsGxsReputationConfigItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsReputationConfigItem", indent); - - out << "mPeerId: " << mPeerId << std::endl; - out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl; - out << "last query : " << time(NULL) - mLastQuery << " secs ago." << std::endl; - - printRsItemEnd(out, "RsReputationConfigItem", indent); - return out; -} - -std::ostream& RsGxsReputationSetItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsReputationSetItem", indent); - - out << "GxsId: " << mGxsId << std::endl; - out << "Owner: " << mOwnerNodeId << std::endl; - out << "mOwnOpinion: " << mOwnOpinion << std::endl; - out << "mOwnOpinionTS : " << time(NULL) - mOwnOpinionTS << " secs ago." << std::endl; - out << "Opinions from neighbors: " << std::endl; - - for(std::map::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it) - out << " " << it->first << ": " << it->second << std::endl; - - printRsItemEnd(out, "RsReputationSetItem", indent); - return out; -} -std::ostream& RsGxsReputationUpdateItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsReputationUpdateItem", indent); - - out << "from: " << PeerId() << std::endl; - out << "last update: " << time(NULL) - mLatestUpdate << " secs ago." << std::endl; - - for(std::map::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it) - out << " " << it->first << ": " << it->second << std::endl; - - printRsItemEnd(out, "RsReputationUpdateItem", indent); - return out; -} -std::ostream& RsGxsReputationRequestItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsReputationRequestItem", indent); - - out << "last update: " << time(NULL) - mLastUpdate << " secs ago." << std::endl; - - printRsItemEnd(out, "RsReputationRequestItem", indent); - return out; -} -std::ostream& RsGxsReputationBannedNodeSetItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsReputationBannedNodeSetItem", indent); - - out << "last update: " << time(NULL) - mLastActivityTS << " secs ago." << std::endl; - out << "PGP id: " << mPgpId << std::endl; - out << "Known ids: " << mKnownIdentities.ids.size() << std::endl; - - printRsItemEnd(out, "RsReputationRequestItem", indent); - return out; -} -/*************************************************************************/ - -uint32_t RsGxsReputationConfigItem::serial_size() const -{ - uint32_t s = 8; /* header */ - - s += mPeerId.serial_size() ; // PeerId - s += 4 ; // mLatestUpdate - s += 4 ; // mLastQuery - - return s ; -} - -uint32_t RsGxsReputationSetItem::serial_size() const -{ - uint32_t s = 8; /* header */ - - s += mGxsId.serial_size() ; - s += 4 ; // mOwnOpinion - s += 4 ; // mOwnOpinionTS - s += 4 ; // mIdentityFlags - s += 4 ; // mLastUsedTS - s += mOwnerNodeId.serial_size() ; - - s += 4 ; // mOpinions.size() - - s += (4+RsPeerId::serial_size()) * mOpinions.size() ; - - return s ; -} - -uint32_t RsGxsReputationBannedNodeSetItem::serial_size() const -{ - uint32_t s = 8; /* header */ - - s += RsPgpId::serial_size() ; // mPgpId - s += 4 ; // mLastActivityTS; - s += mKnownIdentities.TlvSize(); // mKnownIdentities - - return s ; -} - -uint32_t RsGxsReputationUpdateItem::serial_size() const -{ - uint32_t s = 8; /* header */ - - s += 4 ; // mLatestUpdate - s += 4 ; // mOpinions.size(); - - s += (RsGxsId::serial_size() + 4) * mOpinions.size() ; - - return s ; -} - -uint32_t RsGxsReputationRequestItem::serial_size() const -{ - uint32_t s = 8; /* header */ - - s += 4 ; // mLastUpdate - - return s; -} - -/*************************************************************************/ - -bool RsGxsReputationConfigItem::serialise(void *data, uint32_t& pktsize) const -{ - uint32_t tlvsize ; - uint32_t offset=0; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - bool ok = true; - - ok &= mPeerId.serialise(data,tlvsize,offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate); - ok &= setRawUInt32(data, tlvsize, &offset, mLastQuery); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsReputationConfigItem::serialisedata() size error! " << std::endl; - } - - return ok; -} - -bool RsGxsReputationSetItem::serialise(void *data, uint32_t& pktsize) const -{ - uint32_t tlvsize ; - uint32_t offset=0; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - bool ok = true; - - ok &= mGxsId.serialise(data,tlvsize,offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinion); - ok &= setRawUInt32(data, tlvsize, &offset, mOwnOpinionTS); - ok &= setRawUInt32(data, tlvsize, &offset, mIdentityFlags) ; - ok &= setRawUInt32(data, tlvsize, &offset, mLastUsedTS) ; - ok &= mOwnerNodeId.serialise(data,tlvsize,offset) ; - - ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size()); - - for(std::map::const_iterator it(mOpinions.begin());it!=mOpinions.end();++it) - { - ok &= it->first.serialise(data,tlvsize,offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, it->second) ; - } - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl; - } - - return ok; -} - -bool RsGxsReputationBannedNodeSetItem::serialise(void *data, uint32_t& pktsize) const -{ - uint32_t tlvsize ; - uint32_t offset=0; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - bool ok = true; - - ok &= mPgpId.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, mLastActivityTS); - ok &= mKnownIdentities.SetTlv(data, tlvsize, &offset) ; - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsReputationSetItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -bool RsGxsReputationUpdateItem::serialise(void *data, uint32_t& pktsize) const -{ - uint32_t tlvsize ; - uint32_t offset=0; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - bool ok = true; - - ok &= setRawUInt32(data, tlvsize, &offset, mLatestUpdate); - ok &= setRawUInt32(data, tlvsize, &offset, mOpinions.size()); - - for(std::map::const_iterator it(mOpinions.begin());ok && it!=mOpinions.end();++it) - { - ok &= it->first.serialise(data, tlvsize, offset) ; - ok &= setRawUInt32(data, tlvsize, &offset, it->second) ; - } - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsReputationUpdateItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -/* serialise the data to the buffer */ -bool RsGxsReputationRequestItem::serialise(void *data, uint32_t& pktsize) const -{ - uint32_t tlvsize ; - uint32_t offset=0; - - if(!serialise_header(data,pktsize,tlvsize,offset)) - return false ; - - bool ok = true; - - ok &= setRawUInt32(data, tlvsize, &offset, mLastUpdate); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsGxsReputationRequestItem::serialisedata() size error! " << std::endl; - } - - return ok; -} -/*************************************************************************/ - -RsGxsReputationConfigItem *RsGxsReputationSerialiser::deserialiseReputationConfigItem(void *data,uint32_t size) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationConfigItem *item = new RsGxsReputationConfigItem() ; - - /* add mandatory parts first */ - ok &= item->mPeerId.deserialise(data, size, offset) ; - ok &= getRawUInt32(data, size, &offset, &item->mLatestUpdate); - ok &= getRawUInt32(data, size, &offset, &item->mLastQuery); - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} - -RsGxsReputationBannedNodeSetItem *RsGxsReputationSerialiser::deserialiseReputationBannedNodeSetItem(void *data,uint32_t size) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationBannedNodeSetItem *item = new RsGxsReputationBannedNodeSetItem() ; - - /* add mandatory parts first */ - ok &= item->mPgpId.deserialise(data, size, offset) ; - ok &= getRawUInt32(data, size, &offset, &item->mLastActivityTS); - ok &= item->mKnownIdentities.GetTlv(data,size,&offset) ; - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} - - -RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated(void *data,uint32_t tlvsize) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationSetItem *item = new RsGxsReputationSetItem() ; - - /* add mandatory parts first */ - ok &= item->mGxsId.deserialise(data, tlvsize, offset) ; - - item->mOwnerNodeId.clear(); // clears up, for backward compat. - - ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags); - - uint32_t S ; - ok &= getRawUInt32(data, tlvsize, &offset, &S); - - for(uint32_t i = 0; ok && (i < S); ++i) - { - RsPeerId pid ; - uint32_t op ; - - ok &= pid.deserialise(data, tlvsize, offset) ; - ok &= getRawUInt32(data, tlvsize, &offset, &op); - - if(ok) - item->mOpinions[pid] = op ; - } - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -RsGxsReputationSetItem_deprecated3 *RsGxsReputationSerialiser::deserialiseReputationSetItem_deprecated3(void *data,uint32_t tlvsize) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationSetItem_deprecated3 *item = new RsGxsReputationSetItem_deprecated3() ; - - /* add mandatory parts first */ - ok &= item->mGxsId.deserialise(data, tlvsize, offset) ; - ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags); - ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ; - - uint32_t S ; - ok &= getRawUInt32(data, tlvsize, &offset, &S); - - for(uint32_t i = 0; ok && (i < S); ++i) - { - RsPeerId pid ; - uint32_t op ; - - ok &= pid.deserialise(data, tlvsize, offset) ; - ok &= getRawUInt32(data, tlvsize, &offset, &op); - - if(ok) - item->mOpinions[pid] = op ; - } - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} -RsGxsReputationSetItem *RsGxsReputationSerialiser::deserialiseReputationSetItem(void *data,uint32_t tlvsize) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationSetItem *item = new RsGxsReputationSetItem() ; - - /* add mandatory parts first */ - ok &= item->mGxsId.deserialise(data, tlvsize, offset) ; - ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinion); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mOwnOpinionTS); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mIdentityFlags); - ok &= getRawUInt32(data, tlvsize, &offset, &item->mLastUsedTS); - ok &= item->mOwnerNodeId.deserialise(data, tlvsize, offset) ; - - uint32_t S ; - ok &= getRawUInt32(data, tlvsize, &offset, &S); - - for(uint32_t i = 0; ok && (i < S); ++i) - { - RsPeerId pid ; - uint32_t op ; - - ok &= pid.deserialise(data, tlvsize, offset) ; - ok &= getRawUInt32(data, tlvsize, &offset, &op); - - if(ok) - item->mOpinions[pid] = op ; - } - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} - -RsGxsReputationUpdateItem *RsGxsReputationSerialiser::deserialiseReputationUpdateItem(void *data,uint32_t tlvsize) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationUpdateItem *item = new RsGxsReputationUpdateItem() ; - - /* add mandatory parts first */ - ok &= getRawUInt32(data, tlvsize, &offset, &item->mLatestUpdate); - - uint32_t S ; - ok &= getRawUInt32(data, tlvsize, &offset, &S) ; - - for(uint32_t i=0;ok && imOpinions[gid] = op ; - - } - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} - -RsGxsReputationRequestItem *RsGxsReputationSerialiser::deserialiseReputationRequestItem(void *data,uint32_t tlvsize) -{ - uint32_t offset = 8; // skip the header - uint32_t rssize = getRsItemSize(data); - bool ok = true ; - - RsGxsReputationRequestItem *item = new RsGxsReputationRequestItem() ; - - /* add mandatory parts first */ - ok &= getRawUInt32(data, tlvsize, &offset, &item->mLastUpdate); - - if (offset != rssize || !ok) - { - std::cerr << __PRETTY_FUNCTION__ << ": error while deserialising! Item will be dropped." << std::endl; - delete item; - return NULL ; - } - - return item; -} - -/*************************************************************************/ - -RsItem *RsGxsReputationSerialiser::deserialise(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_GXS_TYPE_REPUTATION != getRsItemService(rstype))) - { - std::cerr << "RsReputationSerialiser::deserialise(): wrong item type " << std::hex << rstype << std::dec << std::endl; - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM : return deserialiseReputationSetItem (data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_SET_ITEM_deprecated3: return deserialiseReputationSetItem_deprecated3(data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_BANNED_NODE_SET_ITEM: return deserialiseReputationBannedNodeSetItem (data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_UPDATE_ITEM : return deserialiseReputationUpdateItem (data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_REQUEST_ITEM : return deserialiseReputationRequestItem (data, *pktsize); - case RS_PKT_SUBTYPE_GXS_REPUTATION_CONFIG_ITEM : return deserialiseReputationConfigItem (data, *pktsize); - - default: - std::cerr << "RsGxsReputationSerialiser::deserialise(): unknown item subtype " << std::hex<< rstype << std::dec << std::endl; - return NULL; - break; - } -} -#endif - /*************************************************************************/ RsItem *RsGxsReputationSerialiser::create_item(uint16_t service,uint8_t subtype) const diff --git a/libretroshare/src/rsitems/rshistoryitems.cc b/libretroshare/src/rsitems/rshistoryitems.cc index 3280f8eba..23aa9e38f 100644 --- a/libretroshare/src/rsitems/rshistoryitems.cc +++ b/libretroshare/src/rsitems/rshistoryitems.cc @@ -72,225 +72,4 @@ RsHistoryMsgItem::RsHistoryMsgItem() : RsItem(RS_PKT_VERSION1, RS_PKT_CLASS_CONF saveToDisc = true; } -#ifdef TO_REMOVE -/*************************************************************************/ -RsHistoryMsgItem::~RsHistoryMsgItem() -{ -} - -void RsHistoryMsgItem::clear() -{ - incoming = false; - peerId.clear(); - peerName.clear(); - sendTime = 0; - recvTime = 0; - message.clear(); - msgId = 0; - saveToDisc = true; -} - -std::ostream& RsHistoryMsgItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsHistoryMsgItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "chatPeerid: " << chatPeerId << std::endl; - - printIndent(out, int_Indent); - out << "incoming: " << (incoming ? "1" : "0") << std::endl; - - printIndent(out, int_Indent); - out << "peerId: " << peerId << std::endl; - - printIndent(out, int_Indent); - out << "peerName: " << peerName << std::endl; - - printIndent(out, int_Indent); - out << "sendTime: " << sendTime << std::endl; - - printIndent(out, int_Indent); - out << "recvTime: " << recvTime << std::endl; - - printIndent(out, int_Indent); - std::string cnv_message(message.begin(), message.end()); - out << "message: " << cnv_message << std::endl; - - printRsItemEnd(out, "RsHistoryMsgItem", indent); - return out; -} - - -RsHistorySerialiser::~RsHistorySerialiser() -{ -} - -uint32_t RsHistorySerialiser::sizeHistoryMsgItem(RsHistoryMsgItem* item) -{ - uint32_t s = 8; /* header */ - s += 2; /* version */ - s += item->chatPeerId.serial_size(); - s += 1; /* incoming */ - s += item->peerId.serial_size(); - s += GetTlvStringSize(item->peerName); - s += 4; /* sendTime */ - s += 4; /* recvTime */ - s += GetTlvStringSize(item->message); - - return s; -} -/* serialise the data to the buffer */ -bool RsHistorySerialiser::serialiseHistoryMsgItem(RsHistoryMsgItem* item, void* data, uint32_t* pktsize) -{ - uint32_t tlvsize = sizeHistoryMsgItem(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsHistorySerialiser::serialiseItem() Header: " << ok << std::endl; - std::cerr << "RsHistorySerialiser::serialiseItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt16(data, tlvsize, &offset, 0); // version - ok &= item->chatPeerId.serialise(data, tlvsize, offset) ; - uint8_t dummy = item->incoming ? 1 : 0; - ok &= setRawUInt8(data, tlvsize, &offset, dummy); - ok &= item->peerId.serialise(data, tlvsize, offset) ; - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->peerName); - ok &= setRawUInt32(data, tlvsize, &offset, item->sendTime); - ok &= setRawUInt32(data, tlvsize, &offset, item->recvTime); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->message); - - if (offset != tlvsize) - { - ok = false; -#ifdef RSSERIAL_DEBUG - std::cerr << "RsHistorySerialiser::serialiseItem() Size Error! " << std::endl; -#endif - } - - return ok; -} - -RsHistoryMsgItem *RsHistorySerialiser::deserialiseHistoryMsgItem(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_HISTORY_CONFIG != getRsItemType(rstype)) || - (RS_PKT_SUBTYPE_DEFAULT != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsHistoryMsgItem *item = new RsHistoryMsgItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - uint16_t version = 0; - ok &= getRawUInt16(data, rssize, &offset, &version); - ok &= item->chatPeerId.deserialise(data, rssize, offset) ; - uint8_t dummy; - ok &= getRawUInt8(data, rssize, &offset, &dummy); - item->incoming = (dummy == 1); - ok &= item->peerId.deserialise(data, rssize, offset) ; - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->peerName); - ok &= getRawUInt32(data, rssize, &offset, &(item->sendTime)); - ok &= getRawUInt32(data, rssize, &offset, &(item->recvTime)); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->message); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -uint32_t RsHistorySerialiser::size(RsItem *item) -{ - RsHistoryMsgItem* hi; - - if (NULL != (hi = dynamic_cast(item))) - { - return sizeHistoryMsgItem(hi); - } - - return 0; -} - -bool RsHistorySerialiser::serialise(RsItem *item, void *data, uint32_t *pktsize) -{ - RsHistoryMsgItem* hi; - - if (NULL != (hi = dynamic_cast(item))) - { - return serialiseHistoryMsgItem(hi, data, pktsize); - } - - return false; -} - -RsItem* RsHistorySerialiser::deserialise(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || - (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || - (RS_PKT_TYPE_HISTORY_CONFIG != getRsItemType(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_DEFAULT: - return deserialiseHistoryMsgItem(data, pktsize); - } - - return NULL; -} - -/*************************************************************************/ - -#endif diff --git a/libretroshare/src/rsitems/rsnxsitems.cc b/libretroshare/src/rsitems/rsnxsitems.cc index d6eb8b143..104935930 100644 --- a/libretroshare/src/rsitems/rsnxsitems.cc +++ b/libretroshare/src/rsitems/rsnxsitems.cc @@ -212,1199 +212,4 @@ void RsNxsSessionKeyItem::clear() } #endif -#ifdef TO_REMOVE -uint32_t RsNxsSerialiser::size(RsItem *item) -{ - RsNxsItem *nxs_item = dynamic_cast(item) ; - - if(nxs_item != NULL) - return nxs_item->serial_size() ; - else - { - std::cerr << "RsNxsSerialiser::serialise(): Not an RsNxsItem!" << std::endl; - return 0; - } -} - -bool RsNxsSerialiser::serialise(RsItem *item, void *data, uint32_t *size) -{ - RsNxsItem *nxs_item = dynamic_cast(item) ; - - if(nxs_item != NULL) - return nxs_item->serialise(data,*size) ; - else - { - std::cerr << "RsNxsSerialiser::serialise(): Not an RsNxsItem!" << std::endl; - return 0; - } -} - -bool RsNxsItem::serialise_header(void *data,uint32_t& pktsize,uint32_t& tlvsize, uint32_t& offset) const -{ - tlvsize = serial_size() ; - offset = 0; - - if (pktsize < tlvsize) - return false; /* not enough space */ - - pktsize = tlvsize; - - if(!setRsItemHeader(data, tlvsize, PacketId(), tlvsize)) - { - std::cerr << "RsFileTransferItem::serialise_header(): ERROR. Not enough size!" << std::endl; - return false ; - } -#ifdef RSSERIAL_DEBUG - std::cerr << "RsFileItemSerialiser::serialiseData() Header: " << ok << std::endl; -#endif - offset += 8; - - return true ; -} - -bool RsNxsSyncMsgItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsSynMsgItem()" << std::endl; -#endif - - /* RsNxsSyncMsgItem */ - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt8(data, size, &offset, flag); - ok &= grpId.serialise(data, size, offset); - ok &= msgId.serialise(data, size, offset); - ok &= authorId.serialise(data, size, offset); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsSynMsgItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseNxsSynMsgItem() NOK" << std::endl; - } -#endif - - return ok; -} - -bool RsNxsMsg::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt8(data, size, &offset, pos); - ok &= msgId.serialise(data, size, offset); - ok &= grpId.serialise(data, size, offset); - ok &= msg.SetTlv(data, size, &offset); - ok &= meta.SetTlv(data, size, &offset); - - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsMsg() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseNxsMsg() NOK" << std::endl; - } -#endif - - return ok; -} - - -bool RsNxsGrp::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - // grp id - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt8(data, size, &offset, pos); - ok &= grpId.serialise(data, size, offset); - ok &= grp.SetTlv(data, size, &offset); - ok &= meta.SetTlv(data, size, &offset); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsGrp() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseNxsGrp() NOK" << std::endl; - } -#endif - - return ok; -} -bool RsNxsSyncGrpStatsItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsSyncGrpStats()" << std::endl; -#endif - - ok &= setRawUInt32(data, size, &offset, request_type); - ok &= grpId.serialise(data, size, offset) ; - ok &= setRawUInt32(data, size, &offset, number_of_posts); - ok &= setRawUInt32(data, size, &offset, last_post_TS); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseSyncGrpStats() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseSyncGrpStats() NOK" << std::endl; - } -#endif - - return ok; -} -bool RsNxsSyncGrpReqItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt8(data, size, &offset, flag); - ok &= setRawUInt32(data, size, &offset, createdSince); - ok &= SetTlvString(data, size, &offset, TLV_TYPE_STR_HASH_SHA1, syncHash); - ok &= setRawUInt32(data, size, &offset, updateTS); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseSyncGrp() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseSyncGrp() NOK" << std::endl; - } -#endif - - return ok; -} - -bool RsNxsTransacItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt16(data, size, &offset, transactFlag); - ok &= setRawUInt32(data, size, &offset, nItems); - ok &= setRawUInt32(data, size, &offset, updateTS); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsTrans() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseNxsTrans() NOK" << std::endl; - } -#endif - - return ok; -} - -bool RsNxsSyncGrpItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - /* RsNxsSyncm */ - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt8(data, size, &offset, flag); - ok &= grpId.serialise(data, size, offset); - ok &= setRawUInt32(data, size, &offset, publishTs); - ok &= authorId.serialise(data, size, offset); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsSyncm( FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseNxsSyncm() NOK" << std::endl; - } -#endif - - return ok; -} - - -bool RsNxsSyncMsgReqItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= setRawUInt8(data, size, &offset, flag); - ok &= setRawUInt32(data, size, &offset, createdSinceTS); - ok &= SetTlvString(data, size, &offset, TLV_TYPE_STR_HASH_SHA1, syncHash); - ok &= grpId.serialise(data, size, offset); - ok &= setRawUInt32(data, size, &offset, updateTS); - - if(offset != tlvsize){ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::serialiseNxsSyncMsg() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef RSSERIAL_DEBUG - if (!ok) - { - std::cerr << "RsNxsSerialiser::serialiseNxsSyncMsg( NOK" << std::endl; - } -#endif - - return ok; -} - - -bool RsNxsGroupPublishKeyItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= grpId.serialise(data, size, offset) ; - ok &= private_key.SetTlv(data, size, &offset) ; - - if(offset != tlvsize) - { - std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem() FAIL Size Error! " << std::endl; - ok = false; - } - - if (!ok) - std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem( NOK" << std::endl; - - return ok; -} - -bool RsNxsSessionKeyItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - - if(offset + EVP_MAX_IV_LENGTH >= size) - { - std::cerr << "RsNxsSessionKeyItem::serialize(): error. Not enough room for IV !" << std::endl; - return false ; - } - memcpy(&((uint8_t*)data)[offset],iv,EVP_MAX_IV_LENGTH) ; - offset += EVP_MAX_IV_LENGTH ; - - ok &= setRawUInt32(data, size, &offset, encrypted_session_keys.size()); - - for(std::map::const_iterator it(encrypted_session_keys.begin());it!=encrypted_session_keys.end();++it) - { - ok &= it->first.serialise(data, size, offset) ; - ok &= it->second.SetTlv(data, size, &offset) ; - } - - if(offset != tlvsize) - { - std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem() FAIL Size Error! " << std::endl; - ok = false; - } - - if (!ok) - std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem( NOK" << std::endl; - - return ok; -} -bool RsNxsEncryptedDataItem::serialise(void *data, uint32_t& size) const -{ - uint32_t tlvsize,offset=0; - bool ok = true; - - if(!serialise_header(data,size,tlvsize,offset)) - return false ; - - ok &= setRawUInt32(data, size, &offset, transactionNumber); - ok &= encrypted_data.SetTlv(data, size, &offset) ; - - if(offset != tlvsize) - { - std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem() FAIL Size Error! " << std::endl; - ok = false; - } - - if (!ok) - std::cerr << "RsNxsSerialiser::serialiseGroupPublishKeyItem( NOK" << std::endl; - - return ok; -} - - - -/*** deserialisation ***/ - -RsNxsGrp* RsNxsSerialiser::deserialNxsGrpItem(void *data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_GRP_ITEM); - uint32_t offset = 8; - - RsNxsGrp* item = new RsNxsGrp(SERVICE_TYPE); - - /* skip the header */ - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt8(data, *size, &offset, &(item->pos)); - ok &= item->grpId.deserialise(data, *size, offset); - ok &= item->grp.GetTlv(data, *size, &offset); - ok &= item->meta.GetTlv(data, *size, &offset); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGrp() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGrp() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -RsNxsMsg* RsNxsSerialiser::deserialNxsMsgItem(void *data, uint32_t *size){ - - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_MSG_ITEM); - uint32_t offset = 8; - - RsNxsMsg* item = new RsNxsMsg(SERVICE_TYPE); - /* skip the header */ - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt8(data, *size, &offset, &(item->pos)); - ok &= item->msgId.deserialise(data, *size, offset); - ok &= item->grpId.deserialise(data, *size, offset); - ok &= item->msg.GetTlv(data, *size, &offset); - ok &= item->meta.GetTlv(data, *size, &offset); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsMsg() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsMsg() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -RsNxsSyncGrpStatsItem* RsNxsSerialiser::deserialNxsSyncGrpStatsItem(void *data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_SYNC_GRP_STATS_ITEM); - uint32_t offset = 8; - - RsNxsSyncGrpStatsItem* item = new RsNxsSyncGrpStatsItem(SERVICE_TYPE) ; - /* skip the header */ - - ok &= getRawUInt32(data, *size, &offset, &(item->request_type)); - ok &= item->grpId.deserialise(data, *size, offset) ; - ok &= getRawUInt32(data, *size, &offset, &(item->number_of_posts)); - ok &= getRawUInt32(data, *size, &offset, &(item->last_post_TS)); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncGrpStats() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncGrpStats() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - - -bool RsNxsSerialiser::checkItemHeader(void *data,uint32_t *size,uint8_t subservice_type) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::checkItemHeader()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (SERVICE_TYPE != getRsItemService(rstype)) || (subservice_type != getRsItemSubType(rstype))) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::checkItemHeader() FAIL wrong type" << std::endl; -#endif - return false; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::checkItemHeader() FAIL wrong size" << std::endl; -#endif - return false; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - return true ; -} - -RsNxsSyncGrpReqItem* RsNxsSerialiser::deserialNxsSyncGrpReqItem(void *data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_SYNC_GRP_REQ_ITEM); - - RsNxsSyncGrpReqItem* item = new RsNxsSyncGrpReqItem(SERVICE_TYPE); - /* skip the header */ - uint32_t offset = 8; - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt8(data, *size, &offset, &(item->flag)); - ok &= getRawUInt32(data, *size, &offset, &(item->createdSince)); - ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash); - ok &= getRawUInt32(data, *size, &offset, &(item->updateTS)); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncGrp() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncGrp() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -RsNxsSyncGrpItem* RsNxsSerialiser::deserialNxsSyncGrpItem(void *data, uint32_t *size){ - - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_SYNC_GRP_ITEM); - - RsNxsSyncGrpItem* item = new RsNxsSyncGrpItem(SERVICE_TYPE); - /* skip the header */ - uint32_t offset = 8; - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt8(data, *size, &offset, &(item->flag)); - ok &= item->grpId.deserialise(data, *size, offset); - ok &= getRawUInt32(data, *size, &offset, &(item->publishTs)); - ok &= item->authorId.deserialise(data, *size, offset); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncGrpItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncGrpItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -RsNxsTransacItem* RsNxsSerialiser::deserialNxsTransacItem(void *data, uint32_t *size){ - - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_TRANSAC_ITEM); - uint32_t offset = 8 ; - - RsNxsTransacItem* item = new RsNxsTransacItem(SERVICE_TYPE); - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt16(data, *size, &offset, &(item->transactFlag)); - ok &= getRawUInt32(data, *size, &offset, &(item->nItems)); - ok &= getRawUInt32(data, *size, &offset, &(item->updateTS)); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsTrans() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsTrans() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; - - -} - -RsNxsSyncMsgItem* RsNxsSerialiser::deserialNxsSyncMsgItem(void *data, uint32_t *size){ - - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_SYNC_MSG_ITEM); - uint32_t offset = 8 ; - - RsNxsSyncMsgItem* item = new RsNxsSyncMsgItem(SERVICE_TYPE); - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt8(data, *size, &offset, &(item->flag)); - ok &= item->grpId.deserialise(data, *size, offset); - ok &= item->msgId.deserialise(data, *size, offset); - ok &= item->authorId.deserialise(data, *size, offset); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncMsgItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncMsgItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -RsNxsSyncMsgReqItem* RsNxsSerialiser::deserialNxsSyncMsgReqItem(void *data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_SYNC_MSG_REQ_ITEM); - uint32_t offset = 8 ; - - RsNxsSyncMsgReqItem* item = new RsNxsSyncMsgReqItem(SERVICE_TYPE); - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - ok &= getRawUInt8(data, *size, &offset, &(item->flag)); - ok &= getRawUInt32(data, *size, &offset, &(item->createdSinceTS)); - ok &= GetTlvString(data, *size, &offset, TLV_TYPE_STR_HASH_SHA1, item->syncHash); - ok &= item->grpId.deserialise(data, *size, offset); - ok &= getRawUInt32(data, *size, &offset, &(item->updateTS)); - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncMsg() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsSyncMsg() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} -RsNxsGroupPublishKeyItem* RsNxsSerialiser::deserialNxsGroupPublishKeyItem(void *data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_GRP_PUBLISH_KEY_ITEM); - uint32_t offset = 8 ; - - RsNxsGroupPublishKeyItem* item = new RsNxsGroupPublishKeyItem(SERVICE_TYPE); - - ok &= item->grpId.deserialise(data, *size, offset); - ok &= item->private_key.GetTlv(data, *size, &offset) ; - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -RsNxsSessionKeyItem *RsNxsSerialiser::deserialNxsSessionKeyItem(void* data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_SESSION_KEY_ITEM); - uint32_t offset = 8 ; - - RsNxsSessionKeyItem* item = new RsNxsSessionKeyItem(SERVICE_TYPE); - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - - if(offset + EVP_MAX_IV_LENGTH >= *size) - { - std::cerr << __PRETTY_FUNCTION__ << ": not enough room for IV." << std::endl; - return NULL ; - } - memcpy(item->iv,&((uint8_t*)data)[offset],EVP_MAX_IV_LENGTH) ; - offset += EVP_MAX_IV_LENGTH ; - - uint32_t n ; - ok &= getRawUInt32(data, *size, &offset, &n) ; - - for(uint32_t i=0;ok && iencrypted_session_keys[gxs_id] = bdata ; - } - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} -RsNxsEncryptedDataItem *RsNxsSerialiser::deserialNxsEncryptedDataItem(void* data, uint32_t *size) -{ - bool ok = checkItemHeader(data,size,RS_PKT_SUBTYPE_NXS_ENCRYPTED_DATA_ITEM); - uint32_t offset = 8 ; - - RsNxsEncryptedDataItem* item = new RsNxsEncryptedDataItem(SERVICE_TYPE); - - ok &= getRawUInt32(data, *size, &offset, &(item->transactionNumber)); - item->encrypted_data.tlvtype = TLV_TYPE_BIN_ENCRYPTED ; - - ok &= item->encrypted_data.GetTlv(data,*size,&offset) ; - - if (offset != *size) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef RSSERIAL_DEBUG - std::cerr << "RsNxsSerialiser::deserialNxsGroupPublishKeyItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - -/*** size functions ***/ - - -uint32_t RsNxsMsg::serial_size()const -{ - - uint32_t s = 8; //header size - - s += 4; // transaction number - s += 1; // pos - s += grpId.serial_size(); - s += msgId.serial_size(); - s += msg.TlvSize(); - s += meta.TlvSize(); - - return s; -} - -uint32_t RsNxsGrp::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += 1; // pos - s += grpId.serial_size(); - s += grp.TlvSize(); - s += meta.TlvSize(); - - return s; -} - -uint32_t RsNxsGroupPublishKeyItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += grpId.serial_size() ; - s += private_key.TlvSize(); - - return s; -} -uint32_t RsNxsSyncGrpReqItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += 1; // flag - s += 4; // sync age - s += GetTlvStringSize(syncHash); - s += 4; // updateTS - - return s; -} -uint32_t RsNxsSyncGrpStatsItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // request type - s += grpId.serial_size(); - s += 4; // number_of_posts - s += 4; // last_post_TS - - return s; -} - -uint32_t RsNxsSyncGrpItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += 4; // publishTs - s += 1; // flag - s += grpId.serial_size(); - s += authorId.serial_size(); - - return s; -} - - -uint32_t RsNxsSyncMsgReqItem::serial_size() const -{ - - uint32_t s = 8; - - s += 4; // transaction number - s += 1; // flag - s += 4; // age - s += grpId.serial_size(); - s += GetTlvStringSize(syncHash); - s += 4; // updateTS - - return s; -} - - -uint32_t RsNxsSyncMsgItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += 1; // flag - s += grpId.serial_size(); - s += msgId.serial_size(); - s += authorId.serial_size(); - - return s; -} - -uint32_t RsNxsTransacItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += 2; // flag - s += 4; // nMsgs - s += 4; // updateTS - - return s; -} -uint32_t RsNxsEncryptedDataItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += encrypted_data.TlvSize() ; - - return s; -} -uint32_t RsNxsSessionKeyItem::serial_size() const -{ - uint32_t s = 8; // header size - - s += 4; // transaction number - s += EVP_MAX_IV_LENGTH ; // iv - s += 4 ; // encrypted_session_keys.size() ; - - for(std::map::const_iterator it(encrypted_session_keys.begin());it!=encrypted_session_keys.end();++it) - s += it->first.serial_size() + it->second.TlvSize() ; - - return s; -} - - -std::ostream& RsNxsSyncGrpReqItem::print(std::ostream &out, uint16_t indent) -{ - - printRsItemBase(out, "RsNxsSyncGrp", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out , int_Indent); - out << "Hash: " << syncHash << std::endl; - printIndent(out , int_Indent); - out << "Sync Age: " << createdSince << std::endl; - printIndent(out , int_Indent); - out << "flag: " << (uint32_t) flag << std::endl; - printIndent(out , int_Indent); - out << "updateTS: " << updateTS << std::endl; - - printRsItemEnd(out ,"RsNxsSyncGrp", indent); - - return out; -} -std::ostream& RsNxsGroupPublishKeyItem::print(std::ostream &out, uint16_t indent) -{ - - printRsItemBase(out, "RsNxsGroupPublishKeyItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out , int_Indent); - out << "GroupId: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "keyId: " << private_key.keyId << std::endl; - - printRsItemEnd(out ,"RsNxsGroupPublishKeyItem", indent); - - return out; -} - - -std::ostream& RsNxsSyncMsgReqItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsNxsSyncMsg", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out , int_Indent); - out << "GrpId: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "createdSince: " << createdSinceTS << std::endl; - printIndent(out , int_Indent); - out << "syncHash: " << syncHash << std::endl; - printIndent(out , int_Indent); - out << "flag: " << (uint32_t) flag << std::endl; - printIndent(out , int_Indent); - out << "updateTS: " << updateTS << std::endl; - - printRsItemEnd(out, "RsNxsSyncMsg", indent); - return out; -} - -std::ostream& RsNxsSyncGrpItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsNxsSyncGrpItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out , int_Indent); - out << "flag: " << (uint32_t) flag << std::endl; - printIndent(out , int_Indent); - out << "grpId: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "publishTs: " << publishTs << std::endl; - printIndent(out , int_Indent); - out << "authorId: " << authorId << std::endl; - - printRsItemEnd(out , "RsNxsSyncGrpItem", indent); - return out; -} - - - -std::ostream& RsNxsSyncMsgItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsNxsSyncMsgItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out , int_Indent); - out << "flag: " << (uint32_t) flag << std::endl; - printIndent(out , int_Indent); - out << "grpId: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "msgId: " << msgId << std::endl; - printIndent(out , int_Indent); - out << "authorId: " << authorId << std::endl; - printIndent(out , int_Indent); - - printRsItemEnd(out ,"RsNxsSyncMsgItem", indent); - return out; -} - -RsNxsGrp* RsNxsGrp::clone() const { - RsNxsGrp* grp = new RsNxsGrp(PacketService()); - *grp = *this; - - if(this->metaData) - { - grp->metaData = new RsGxsGrpMetaData(); -// *(grp->metaData) = *(this->metaData); - } - - return grp; -} - -std::ostream& RsNxsGrp::print(std::ostream &out, uint16_t indent){ - - printRsItemBase(out, "RsNxsGrp", indent); - uint16_t int_Indent = indent + 2; - - out << "grpId: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "grp: " << std::endl; - printIndent(out , int_Indent); - out << "pos: " << pos << std::endl; - grp.print(out, int_Indent); - out << "meta: " << std::endl; - meta.print(out, int_Indent); - - printRsItemEnd(out, "RsNxsGrp", indent); - return out; -} - -std::ostream& RsNxsMsg::print(std::ostream &out, uint16_t indent){ - - printRsItemBase(out, "RsNxsMsg", indent); - uint16_t int_Indent = indent + 2; - - out << "msgId: " << msgId << std::endl; - printIndent(out , int_Indent); - out << "grpId: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "pos: " << pos << std::endl; - printIndent(out , int_Indent); - out << "msg: " << std::endl; - msg.print(out, indent); - out << "meta: " << std::endl; - meta.print(out, int_Indent); - - printRsItemEnd(out ,"RsNxsMsg", indent); - return out; -} - -std::ostream& RsNxsSyncGrpStatsItem::print(std::ostream &out, uint16_t indent){ - - printRsItemBase(out, "RsNxsSyncGrpStats", indent); - uint16_t int_Indent = indent + 2; - - out << "available posts: " << number_of_posts << std::endl; - printIndent(out , int_Indent); - out << "last update: " << last_post_TS << std::endl; - printIndent(out , int_Indent); - out << "group ID: " << grpId << std::endl; - printIndent(out , int_Indent); - out << "request type: " << request_type << std::endl; - printIndent(out , int_Indent); - - printRsItemEnd(out ,"RsNxsSyncGrpStats", indent); - return out; -} -std::ostream& RsNxsTransacItem::print(std::ostream &out, uint16_t indent){ - - printRsItemBase(out, "RsNxsTransac", indent); - uint16_t int_Indent = indent + 2; - - out << "transactFlag: " << transactFlag << std::endl; - printIndent(out , int_Indent); - out << "nItems: " << nItems << std::endl; - printIndent(out , int_Indent); - out << "timeout: " << timestamp << std::endl; - printIndent(out , int_Indent); - out << "updateTS: " << updateTS << std::endl; - printIndent(out , int_Indent); - out << "transactionNumber: " << transactionNumber << std::endl; - printIndent(out , int_Indent); - - printRsItemEnd(out ,"RsNxsTransac", indent); - return out; -} -std::ostream& RsNxsSessionKeyItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsNxsSessionKeyItem", indent); - - out << " iv: " << RsUtil::BinToHex((char*)iv,EVP_MAX_IV_LENGTH) << std::endl; - - out << " encrypted keys: " << std::endl; - - for(std::map::const_iterator it(encrypted_session_keys.begin());it!=encrypted_session_keys.end();++it) - out << " id=" << it->first << ": ekey=" << RsUtil::BinToHex((char*)it->second.bin_data,it->second.bin_len) << std::endl; - - printRsItemEnd(out ,"RsNxsSessionKeyItem", indent); - return out; -} -std::ostream& RsNxsEncryptedDataItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsNxsEncryptedDataItem", indent); - - out << " encrypted data: " << RsUtil::BinToHex((char*)encrypted_data.bin_data,std::min(50u,encrypted_data.bin_len)) ; - - if(encrypted_data.bin_len > 50u) - out << "..." ; - - out << std::endl; - - printRsItemEnd(out ,"RsNxsSessionKeyItem", indent); - return out; -} -#endif diff --git a/libretroshare/src/rsitems/rsrttitems.cc b/libretroshare/src/rsitems/rsrttitems.cc index c4c499f79..033975a3b 100644 --- a/libretroshare/src/rsitems/rsrttitems.cc +++ b/libretroshare/src/rsitems/rsrttitems.cc @@ -63,339 +63,5 @@ void RsRttPongItem::serial_process(RsGenericSerializer::SerializeJob j,RsGeneric RsTypeSerializer::serial_process(j,ctx,mPongTS,"mPongTS") ; } -#ifdef TO_REMOVE -RsRttPingItem::~RsRttPingItem() -{ - return; -} -void RsRttPingItem::clear() -{ - mSeqNo = 0; - mPingTS = 0; -} - -std::ostream& RsRttPingItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsRttPingItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "SeqNo: " << mSeqNo << std::endl; - - printIndent(out, int_Indent); - out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl; - - printRsItemEnd(out, "RsRttPingItem", indent); - return out; -} - - - - - -RsRttPongItem::~RsRttPongItem() -{ - return; -} - -void RsRttPongItem::clear() -{ - mSeqNo = 0; - mPingTS = 0; - mPongTS = 0; -} - - -std::ostream& RsRttPongItem::print(std::ostream &out, uint16_t indent) -{ - printRsItemBase(out, "RsRttPongItem", indent); - uint16_t int_Indent = indent + 2; - printIndent(out, int_Indent); - out << "SeqNo: " << mSeqNo << std::endl; - - printIndent(out, int_Indent); - out << "PingTS: " << std::hex << mPingTS << std::dec << std::endl; - - printIndent(out, int_Indent); - out << "PongTS: " << std::hex << mPongTS << std::dec << std::endl; - - printRsItemEnd(out, "RsRttPongItem", indent); - return out; -} - - -/*************************************************************************/ - - -uint32_t RsRttSerialiser::sizeRttPingItem(RsRttPingItem */*item*/) -{ - uint32_t s = 8; /* header */ - s += 4; /* seqno */ - s += 8; /* pingTS */ - - return s; -} - -/* serialise the data to the buffer */ -bool RsRttSerialiser::serialiseRttPingItem(RsRttPingItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeRttPingItem(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsRttSerialiser::serialiseRttPingItem() Header: " << ok << std::endl; - std::cerr << "RsRttSerialiser::serialiseRttPingItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, item->mSeqNo); - ok &= setRawUInt64(data, tlvsize, &offset, item->mPingTS); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsRttSerialiser::serialiseRttPingItem() Size Error! " << std::endl; - } - - return ok; -} - -RsRttPingItem *RsRttSerialiser::deserialiseRttPingItem(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_RTT != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_RTT_PING != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsRttPingItem *item = new RsRttPingItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->mSeqNo)); - ok &= getRawUInt64(data, rssize, &offset, &(item->mPingTS)); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ -/*************************************************************************/ - - -uint32_t RsRttSerialiser::sizeRttPongItem(RsRttPongItem */*item*/) -{ - uint32_t s = 8; /* header */ - s += 4; /* seqno */ - s += 8; /* pingTS */ - s += 8; /* pongTS */ - - return s; -} - -/* serialise the data to the buffer */ -bool RsRttSerialiser::serialiseRttPongItem(RsRttPongItem *item, void *data, uint32_t *pktsize) -{ - uint32_t tlvsize = sizeRttPongItem(item); - uint32_t offset = 0; - - if (*pktsize < tlvsize) - return false; /* not enough space */ - - *pktsize = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - -#ifdef RSSERIAL_DEBUG - std::cerr << "RsRttSerialiser::serialiseRttPongItem() Header: " << ok << std::endl; - std::cerr << "RsRttSerialiser::serialiseRttPongItem() Size: " << tlvsize << std::endl; -#endif - - /* skip the header */ - offset += 8; - - /* add mandatory parts first */ - ok &= setRawUInt32(data, tlvsize, &offset, item->mSeqNo); - ok &= setRawUInt64(data, tlvsize, &offset, item->mPingTS); - ok &= setRawUInt64(data, tlvsize, &offset, item->mPongTS); - - if (offset != tlvsize) - { - ok = false; - std::cerr << "RsRttSerialiser::serialiseRttPongItem() Size Error! " << std::endl; - } - - return ok; -} - -RsRttPongItem *RsRttSerialiser::deserialiseRttPongItem(void *data, uint32_t *pktsize) -{ - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_RTT != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_RTT_PONG != getRsItemSubType(rstype))) - { - return NULL; /* wrong type */ - } - - if (*pktsize < rssize) /* check size */ - return NULL; /* not enough data */ - - /* set the packet length */ - *pktsize = rssize; - - bool ok = true; - - /* ready to load */ - RsRttPongItem *item = new RsRttPongItem(); - item->clear(); - - /* skip the header */ - offset += 8; - - /* get mandatory parts first */ - ok &= getRawUInt32(data, rssize, &offset, &(item->mSeqNo)); - ok &= getRawUInt64(data, rssize, &offset, &(item->mPingTS)); - ok &= getRawUInt64(data, rssize, &offset, &(item->mPongTS)); - - if (offset != rssize) - { - /* error */ - delete item; - return NULL; - } - - if (!ok) - { - delete item; - return NULL; - } - - return item; -} - -/*************************************************************************/ - -uint32_t RsRttSerialiser::size(RsItem *i) -{ - RsRttPingItem *ping; - RsRttPongItem *pong; - - if (NULL != (ping = dynamic_cast(i))) - { - return sizeRttPingItem(ping); - } - else if (NULL != (pong = dynamic_cast(i))) - { - return sizeRttPongItem(pong); - } - return 0; -} - -bool RsRttSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsMsgSerialiser::serialise()" << std::endl; -#endif - - RsRttPingItem *ping; - RsRttPongItem *pong; - - if (NULL != (ping = dynamic_cast(i))) - { - return serialiseRttPingItem(ping, data, pktsize); - } - else if (NULL != (pong = dynamic_cast(i))) - { - return serialiseRttPongItem(pong, data, pktsize); - } - return false; -} - -RsItem* RsRttSerialiser::deserialise(void *data, uint32_t *pktsize) -{ -#ifdef RSSERIAL_DEBUG - std::cerr << "RsRttSerialiser::deserialise()" << std::endl; -#endif - - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_TYPE_RTT != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - case RS_PKT_SUBTYPE_RTT_PING: - return deserialiseRttPingItem(data, pktsize); - break; - case RS_PKT_SUBTYPE_RTT_PONG: - return deserialiseRttPongItem(data, pktsize); - break; - default: - return NULL; - break; - } - - return NULL; -} - - -/*************************************************************************/ -#endif diff --git a/libretroshare/src/rsitems/rswikiitems.cc b/libretroshare/src/rsitems/rswikiitems.cc index ec42e14f0..96f9e2768 100644 --- a/libretroshare/src/rsitems/rswikiitems.cc +++ b/libretroshare/src/rsitems/rswikiitems.cc @@ -46,94 +46,6 @@ RsItem *RsGxsWikiSerialiser::create_item(uint16_t service, uint8_t item_sub_id) } } -#ifdef TO_REMOVE -uint32_t RsGxsWikiSerialiser::size(RsItem *item) -{ - RsGxsWikiCollectionItem* grp_item = NULL; - RsGxsWikiSnapshotItem* snap_item = NULL; - RsGxsWikiCommentItem* com_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return sizeGxsWikiCollectionItem(grp_item); - } - else if((snap_item = dynamic_cast(item)) != NULL) - { - return sizeGxsWikiSnapshotItem(snap_item); - } - else if((com_item = dynamic_cast(item)) != NULL) - { - return sizeGxsWikiCommentItem(com_item); - } - return 0; -} - -bool RsGxsWikiSerialiser::serialise(RsItem *item, void *data, uint32_t *size) -{ - RsGxsWikiCollectionItem* grp_item = NULL; - RsGxsWikiSnapshotItem* snap_item = NULL; - RsGxsWikiCommentItem* com_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsWikiCollectionItem(grp_item, data, size); - } - else if((snap_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsWikiSnapshotItem(snap_item, data, size); - } - else if((com_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsWikiCommentItem(com_item, data, size); - } - return false; -} - -RsItem* RsGxsWikiSerialiser::deserialise(void* data, uint32_t* size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - - case RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM: - return deserialiseGxsWikiCollectionItem(data, size); - break; - case RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM: - return deserialiseGxsWikiSnapshotItem(data, size); - break; - case RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM: - return deserialiseGxsWikiCommentItem(data, size); - break; - default: -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialise(): unknown subtype"; - std::cerr << std::endl; -#endif - break; - } - return NULL; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#endif - void RsGxsWikiCollectionItem::clear() { collection.mDescription.clear(); @@ -141,38 +53,6 @@ void RsGxsWikiCollectionItem::clear() collection.mHashTags.clear(); } -#ifdef TO_REMOVE -std::ostream& RsGxsWikiCollectionItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsWikiCollectionItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Description: " << collection.mDescription << std::endl; - printIndent(out, int_Indent); - out << "Category: " << collection.mCategory << std::endl; - printIndent(out, int_Indent); - out << "HashTags: " << collection.mHashTags << std::endl; - - printRsItemEnd(out ,"RsGxsWikiCollectionItem", indent); - return out; -} - - -uint32_t RsGxsWikiSerialiser::sizeGxsWikiCollectionItem(RsGxsWikiCollectionItem *item) -{ - - const RsWikiCollection& collection = item->collection; - uint32_t s = 8; // header - - s += GetTlvStringSize(collection.mDescription); - s += GetTlvStringSize(collection.mCategory); - s += GetTlvStringSize(collection.mHashTags); - - return s; -} -#endif - void RsGxsWikiCollectionItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR ,collection.mDescription,"collection.mDescription") ; @@ -180,448 +60,25 @@ void RsGxsWikiCollectionItem::serial_process(RsGenericSerializer::SerializeJob j RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,collection.mHashTags ,"collection.mHashTags") ; } -#ifdef TO_REMOVE -bool RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem(RsGxsWikiCollectionItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsWikiCollectionItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsWikiCollectionItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->collection.mDescription); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_CATEGORY, item->collection.mCategory); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->collection.mHashTags); - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCollectionItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsWikiCollectionItem* RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem(void *data, uint32_t *size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_WIKI_COLLECTION_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsWikiCollectionItem* item = new RsGxsWikiCollectionItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->collection.mDescription); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_CATEGORY, item->collection.mCategory); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->collection.mHashTags); - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCollectionItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#endif - void RsGxsWikiSnapshotItem::clear() { snapshot.mPage.clear(); snapshot.mHashTags.clear(); } -#ifdef TO_REMOVE -std::ostream& RsGxsWikiSnapshotItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsWikiSnapshotItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Page: " << snapshot.mPage << std::endl; - - printIndent(out, int_Indent); - out << "HashTags: " << snapshot.mHashTags << std::endl; - - printRsItemEnd(out ,"RsGxsWikiSnapshotItem", indent); - return out; -} - - -uint32_t RsGxsWikiSerialiser::sizeGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item) -{ - - const RsWikiSnapshot& snapshot = item->snapshot; - uint32_t s = 8; // header - - s += GetTlvStringSize(snapshot.mPage); - s += GetTlvStringSize(snapshot.mHashTags); - - return s; -} -#endif - void RsGxsWikiSnapshotItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_WIKI_PAGE,snapshot.mPage,"snapshot.mPage") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG ,snapshot.mPage,"snapshot.mHashTags") ; } -#ifdef TO_REMOVE -bool RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem(RsGxsWikiSnapshotItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsWikiSnapshotItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsWikiSnapshotItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_WIKI_PAGE, item->snapshot.mPage); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->snapshot.mHashTags); - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiSnapshotItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsWikiSnapshotItem* RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem(void *data, uint32_t *size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_WIKI_SNAPSHOT_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsWikiSnapshotItem* item = new RsGxsWikiSnapshotItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_WIKI_PAGE, item->snapshot.mPage); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->snapshot.mHashTags); - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiSnapshotItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#endif - void RsGxsWikiCommentItem::clear() { comment.mComment.clear(); } -#ifdef TO_REMOVE -std::ostream& RsGxsWikiCommentItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsWikiCommentItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Comment: " << comment.mComment << std::endl; - - printRsItemEnd(out ,"RsGxsWikiCommentItem", indent); - return out; -} - - -uint32_t RsGxsWikiSerialiser::sizeGxsWikiCommentItem(RsGxsWikiCommentItem *item) -{ - - const RsWikiComment& comment = item->comment; - uint32_t s = 8; // header - - s += GetTlvStringSize(comment.mComment); - - return s; -} -#endif - void RsGxsWikiCommentItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_COMMENT,comment.mComment,"comment.mComment") ; } -#ifdef TO_REMOVE -bool RsGxsWikiSerialiser::serialiseGxsWikiCommentItem(RsGxsWikiCommentItem *item, void *data, uint32_t *size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsWikiCommentItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsWikiCommentItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment); - - if(offset != tlvsize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef GXSID_DEBUG - if (!ok) - { - std::cerr << "RsGxsWikiSerialiser::serialiseGxsWikiCommentItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsWikiCommentItem* RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem(void *data, uint32_t *size) -{ - -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIKI != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_WIKI_COMMENT_ITEM != getRsItemSubType(rstype))) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsWikiCommentItem* item = new RsGxsWikiCommentItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_COMMENT, item->comment.mComment); - - if (offset != rssize) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef GXSID_DEBUG - std::cerr << "RsGxsWikiSerialiser::deserialiseGxsWikiCommentItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - -#endif diff --git a/libretroshare/src/rsitems/rswireitems.cc b/libretroshare/src/rsitems/rswireitems.cc index 55a56a803..7a8008ff8 100644 --- a/libretroshare/src/rsitems/rswireitems.cc +++ b/libretroshare/src/rsitems/rswireitems.cc @@ -46,398 +46,19 @@ RsItem *RsGxsWireSerialiser::create_item(uint16_t service,uint8_t item_subtype) } } -#ifdef TO_REMOVE -uint32_t RsGxsWireSerialiser::size(RsItem *item) -{ - RsGxsWireGroupItem* grp_item = NULL; - RsGxsWirePulseItem* snap_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return sizeGxsWireGroupItem(grp_item); - } - else if((snap_item = dynamic_cast(item)) != NULL) - { - return sizeGxsWirePulseItem(snap_item); - } - return 0; -} - -bool RsGxsWireSerialiser::serialise(RsItem *item, void *data, uint32_t *size) -{ - RsGxsWireGroupItem* grp_item = NULL; - RsGxsWirePulseItem* snap_item = NULL; - - if((grp_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsWireGroupItem(grp_item, data, size); - } - else if((snap_item = dynamic_cast(item)) != NULL) - { - return serialiseGxsWirePulseItem(snap_item, data, size); - } - return false; -} - -RsItem* RsGxsWireSerialiser::deserialise(void* data, uint32_t* size) -{ - -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialise()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype))) - { - return NULL; /* wrong type */ - } - - switch(getRsItemSubType(rstype)) - { - - case RS_PKT_SUBTYPE_WIRE_GROUP_ITEM: - return deserialiseGxsWireGroupItem(data, size); - break; - case RS_PKT_SUBTYPE_WIRE_PULSE_ITEM: - return deserialiseGxsWirePulseItem(data, size); - break; - default: -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialise(): unknown subtype"; - std::cerr << std::endl; -#endif - break; - } - return NULL; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#endif - void RsGxsWireGroupItem::clear() { group.mDescription.clear(); } -#ifdef TO_REMOVE -std::ostream& RsGxsWireGroupItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsWireGroupItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Description: " << group.mDescription << std::endl; - - printRsItemEnd(out ,"RsGxsWireGroupItem", indent); - return out; -} - - -uint32_t RsGxsWireSerialiser::sizeGxsWireGroupItem(RsGxsWireGroupItem *item) -{ - - const RsWireGroup& group = item->group; - uint32_t s = 8; // header - - s += GetTlvStringSize(group.mDescription); - - return s; -} - -#endif - void RsGxsWireGroupItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_DESCR,group.mDescription,"group.mDescription") ; } -#ifdef TO_REMOVE -bool RsGxsWireSerialiser::serialiseGxsWireGroupItem(RsGxsWireGroupItem *item, void *data, uint32_t *size) -{ - -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsWireGroupItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsWireGroupItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_DESCR, item->group.mDescription); - - if(offset != tlvsize) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef WIRE_DEBUG - if (!ok) - { - std::cerr << "RsGxsWireSerialiser::serialiseGxsWireGroupItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsWireGroupItem* RsGxsWireSerialiser::deserialiseGxsWireGroupItem(void *data, uint32_t *size) -{ - -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_WIRE_GROUP_ITEM != getRsItemSubType(rstype))) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsWireGroupItem* item = new RsGxsWireGroupItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_DESCR, item->group.mDescription); - - if (offset != rssize) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWireGroupItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - - -void RsGxsWirePulseItem::clear() -{ - pulse.mPulseText.clear(); - pulse.mHashTags.clear(); -} - -std::ostream& RsGxsWirePulseItem::print(std::ostream& out, uint16_t indent) -{ - printRsItemBase(out, "RsGxsWirePulseItem", indent); - uint16_t int_Indent = indent + 2; - - printIndent(out, int_Indent); - out << "Page: " << pulse.mPulseText << std::endl; - - printIndent(out, int_Indent); - out << "HashTags: " << pulse.mHashTags << std::endl; - - printRsItemEnd(out ,"RsGxsWirePulseItem", indent); - return out; -} - - -uint32_t RsGxsWireSerialiser::sizeGxsWirePulseItem(RsGxsWirePulseItem *item) -{ - - const RsWirePulse& pulse = item->pulse; - uint32_t s = 8; // header - - s += GetTlvStringSize(pulse.mPulseText); - s += GetTlvStringSize(pulse.mHashTags); - - return s; -} - -#endif - void RsGxsWirePulseItem::serial_process(RsGenericSerializer::SerializeJob j,RsGenericSerializer::SerializeContext& ctx) { RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_MSG,pulse.mPulseText,"pulse.mPulseText") ; RsTypeSerializer::serial_process(j,ctx,TLV_TYPE_STR_HASH_TAG,pulse.mHashTags,"pulse.mHashTags") ; } -#ifdef TO_REMOVE -bool RsGxsWireSerialiser::serialiseGxsWirePulseItem(RsGxsWirePulseItem *item, void *data, uint32_t *size) -{ - -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl; -#endif - - uint32_t tlvsize = sizeGxsWirePulseItem(item); - uint32_t offset = 0; - - if(*size < tlvsize) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem()" << std::endl; -#endif - return false; - } - - *size = tlvsize; - - bool ok = true; - - ok &= setRsItemHeader(data, tlvsize, item->PacketId(), tlvsize); - - /* skip the header */ - offset += 8; - - /* GxsWirePulseItem */ - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_MSG, item->pulse.mPulseText); - ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_HASH_TAG, item->pulse.mHashTags); - - if(offset != tlvsize) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() FAIL Size Error! " << std::endl; -#endif - ok = false; - } - -#ifdef WIRE_DEBUG - if (!ok) - { - std::cerr << "RsGxsWireSerialiser::serialiseGxsWirePulseItem() NOK" << std::endl; - } -#endif - - return ok; - } - -RsGxsWirePulseItem* RsGxsWireSerialiser::deserialiseGxsWirePulseItem(void *data, uint32_t *size) -{ - -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem()" << std::endl; -#endif - /* get the type and size */ - uint32_t rstype = getRsItemId(data); - uint32_t rssize = getRsItemSize(data); - - uint32_t offset = 0; - - - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || - (RS_SERVICE_GXS_TYPE_WIRE != getRsItemService(rstype)) || - (RS_PKT_SUBTYPE_WIRE_PULSE_ITEM != getRsItemSubType(rstype))) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong type" << std::endl; -#endif - return NULL; /* wrong type */ - } - - if (*size < rssize) /* check size */ - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL wrong size" << std::endl; -#endif - return NULL; /* not enough data */ - } - - /* set the packet length */ - *size = rssize; - - bool ok = true; - - RsGxsWirePulseItem* item = new RsGxsWirePulseItem(); - /* skip the header */ - offset += 8; - - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_MSG, item->pulse.mPulseText); - ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_HASH_TAG, item->pulse.mHashTags); - - if (offset != rssize) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() FAIL size mismatch" << std::endl; -#endif - /* error */ - delete item; - return NULL; - } - - if (!ok) - { -#ifdef WIRE_DEBUG - std::cerr << "RsGxsWireSerialiser::deserialiseGxsWirePulseItem() NOK" << std::endl; -#endif - delete item; - return NULL; - } - - return item; -} - - -/*****************************************************************************************/ -/*****************************************************************************************/ -/*****************************************************************************************/ - -#endif