mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-25 23:06:10 -05:00
fixed a few bugs in config items
This commit is contained in:
parent
fcabe6359f
commit
43b3b87782
@ -40,12 +40,12 @@
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
RsItem *RsFileConfigSerialiser::create_item(uint8_t item_class,uint8_t item_type) const
|
||||
RsItem *RsFileConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_class != RS_PKT_CLASS_CONFIG)
|
||||
if(item_type != RS_PKT_TYPE_FILE_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
switch(item_type)
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_FILE_TRANSFER: return new RsFileTransfer() ;
|
||||
case RS_PKT_SUBTYPE_FILE_ITEM: return new RsFileConfigItem() ;
|
||||
@ -590,12 +590,12 @@ RsGeneralConfigSerialiser::~RsGeneralConfigSerialiser()
|
||||
|
||||
#endif
|
||||
|
||||
RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_class,uint8_t item_type) const
|
||||
RsItem *RsGeneralConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_class != RS_PKT_TYPE_GENERAL_CONFIG)
|
||||
if(item_type != RS_PKT_TYPE_GENERAL_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
switch(item_type)
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_KEY_VALUE: return new RsConfigKeyValueSet();
|
||||
default:
|
||||
@ -818,12 +818,12 @@ RsPeerConfigSerialiser::~RsPeerConfigSerialiser()
|
||||
}
|
||||
#endif
|
||||
|
||||
RsItem *RsPeerConfigSerialiser::create_item(uint8_t item_class,uint8_t item_type) const
|
||||
RsItem *RsPeerConfigSerialiser::create_item(uint8_t item_type,uint8_t item_subtype) const
|
||||
{
|
||||
if(item_class != RS_PKT_TYPE_PEER_CONFIG)
|
||||
if(item_type != RS_PKT_TYPE_PEER_CONFIG)
|
||||
return NULL ;
|
||||
|
||||
switch(item_type)
|
||||
switch(item_subtype)
|
||||
{
|
||||
case RS_PKT_SUBTYPE_PEER_NET: return new RsPeerNetItem();
|
||||
case RS_PKT_SUBTYPE_PEER_STUN: return new RsPeerStunItem();
|
||||
@ -1824,7 +1824,30 @@ uint32_t RsPeerConfigSerialiser::sizePermissions(RsPeerServicePermissionItem *i)
|
||||
|
||||
void RsPeerServicePermissionItem::serial_process(SerializeJob j,SerializeContext& ctx)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,pgp_ids,"pgp_ids") ;
|
||||
// We need to hack this because of backward compatibility. The correct way to do it would be:
|
||||
//
|
||||
// RsTypeSerializer::serial_process(j,ctx,pgp_ids,"pgp_ids") ;
|
||||
// RsTypeSerializer::serial_process(j,ctx,service_flags,"service_flags") ;
|
||||
|
||||
if(j == RsItem::DESERIALIZE)
|
||||
{
|
||||
uint32_t v=0 ;
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,v,"pgp_ids.size()") ;
|
||||
|
||||
pgp_ids.resize(v) ;
|
||||
service_flags.resize(v) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t s = pgp_ids.size();
|
||||
RsTypeSerializer::serial_process<uint32_t>(j,ctx,s,"pgp_ids.size()") ;
|
||||
}
|
||||
|
||||
for(uint32_t i=0;i<pgp_ids.size();++i)
|
||||
{
|
||||
RsTypeSerializer::serial_process(j,ctx,pgp_ids[i],"pgp_ids[i]") ;
|
||||
RsTypeSerializer::serial_process(j,ctx,service_flags[i],"service_flags[i]") ;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TO_REMOVE
|
||||
|
@ -66,8 +66,6 @@ const uint8_t RS_PKT_SUBTYPE_FILE_ITEM = 0x03;
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
// We should make these items use a clean serialise code, and all derive from the same item type.
|
||||
|
||||
class RsPeerNetItem: public RsItem
|
||||
{
|
||||
public:
|
||||
@ -211,7 +209,7 @@ class RsPeerConfigSerialiser: public RsConfigSerializer
|
||||
|
||||
virtual ~RsPeerConfigSerialiser(){}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_class,uint8_t item_type) const ;
|
||||
virtual RsItem *create_item(uint8_t item_type, uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
@ -347,7 +345,7 @@ class RsFileConfigSerialiser: public RsConfigSerializer
|
||||
RsFileConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_FILE_CONFIG) { }
|
||||
virtual ~RsFileConfigSerialiser() {}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_class,uint8_t item_type) const ;
|
||||
virtual RsItem *create_item(uint8_t item_type, uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
/**************************************************************************/
|
||||
@ -372,7 +370,7 @@ class RsGeneralConfigSerialiser: public RsConfigSerializer
|
||||
public:
|
||||
RsGeneralConfigSerialiser() :RsConfigSerializer(RS_PKT_CLASS_CONFIG, RS_PKT_TYPE_GENERAL_CONFIG) {}
|
||||
|
||||
virtual RsItem *create_item(uint8_t item_class,uint8_t item_type) const ;
|
||||
virtual RsItem *create_item(uint8_t item_type, uint8_t item_subtype) const ;
|
||||
};
|
||||
|
||||
#endif /* RS_CONFIG_ITEMS_SERIALISER_H */
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <typeinfo>
|
||||
|
||||
#include "util/rsprint.h"
|
||||
#include "serialization/rsserializer.h"
|
||||
#include "serialization/rstypeserializer.h"
|
||||
@ -14,7 +16,7 @@ RsItem *RsServiceSerializer::deserialise(void *data, uint32_t *size)
|
||||
|
||||
if(!item)
|
||||
{
|
||||
std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl;
|
||||
std::cerr << "(EE) " << typeid(*this).name() << ": cannot deserialise unknown item subtype " << std::hex << getRsItemSubType(rstype) << std::dec << std::endl;
|
||||
std::cerr << "(EE) Data is: " << RsUtil::BinToHex(static_cast<uint8_t*>(data),std::min(50u,*size)) << ((*size>50)?"...":"") << std::endl;
|
||||
return NULL ;
|
||||
}
|
||||
@ -40,11 +42,11 @@ RsItem *RsConfigSerializer::deserialise(void *data, uint32_t *size)
|
||||
{
|
||||
uint32_t rstype = getRsItemId(const_cast<void*>((const void*)data)) ;
|
||||
|
||||
RsItem *item = create_item(getRsItemClass(rstype),getRsItemSubType(rstype)) ;
|
||||
RsItem *item = create_item(getRsItemType(rstype),getRsItemSubType(rstype)) ;
|
||||
|
||||
if(!item)
|
||||
{
|
||||
std::cerr << "(EE) cannot deserialise: unknown item type " << std::hex << rstype << std::dec << std::endl;
|
||||
std::cerr << "(EE) " << typeid(*this).name() << ": cannot deserialise unknown item subtype " << std::hex << getRsItemSubType(rstype) << std::dec << std::endl;
|
||||
std::cerr << "(EE) Data is: " << RsUtil::BinToHex(static_cast<uint8_t*>(data),std::min(50u,*size)) << ((*size>50)?"...":"") << std::endl;
|
||||
return NULL ;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user